Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
[Solved] REGEX headache
Please, could you be so kind to help me with this REGEX?
I can’t retrieve into an evaluate for my <txp:title /> what this regex returns: only the highlight results in any cases (I think I’m going to be crazy):
https://regex101.com/r/KCTBrA/2
<txp:title trim="/(.*)(@\s?)(.*[^(\s\(\d+\))])/" replace='$1 by $3' />
Last edited by Pat64 (2020-08-07 11:00:14)
Patrick.
Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.
Offline
Re: [Solved] REGEX headache
Bump!
😢
Patrick.
Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.
Offline
Re: [Solved] REGEX headache
Hi Patrick,
I’m not quite sure what you want to achieve. I just tried your example code in the textpattern demo (release-demo) and named the two article titles as you had on regex 101 and it seems to work (FWIW with and without escape=""
). I get:
h1: Second Title@ First Name Last Name
h2: Second Title by First Name Last Name
h1: Title@ First Name Last Name (12)
h2: Title by First Name Last Name (12)
Is that not what you want?
If you just want the name without the title, use replace="$3"
(double quotes should be ok for the replace attribute).
If you want just “First Name Last Name” without the number in brackets, try
trim="/(.*)(@\s?)(.*[^(\s\(\d+\))])(\s\(\d+\))?/" replace="$3"
TXP Builders – finely-crafted code, design and txp
Offline
Re: [Solved] REGEX headache
Thank you lot for your interest and your effort, Julian ;)
I want to display my titles without any signs (no @ neither the numbers surrounding by brackets)
Patrick.
Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.
Offline
Re: [Solved] REGEX headache
Oh wait!
What did you do, Julian? Are you a kind of magician?
That works: https://regex101.com/r/LrYEIq/1
You save my day, Julian.
Do you have a PayPal account. I want to send you a few euros for your kindly and appreciate help.
Patrick.
Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.
Offline
Offline
Re: [Solved] REGEX headache
Pat64 wrote #325225:
Oh wait! What did you do, Julian? Are you a kind of magician?
:-) I updated your regex (v3): https://regex101.com/r/KCTBrA/3
Actually you did all the hard work. That regex site is useful as it shows you on the right-hand side all the match values. You just had too many segment matches in the replace section. I first tried sticking the numbers at the end but it didn’t work for your second case, then I tried with ?
as optional at the end but it didn’t work in both cases. So I used what you started with and the optional number in brackets at the end.
There is likely a more succinct version of that but I didn’t look any further :) EDIT: but Oleg did :-)
Glad to help out, no PayPal necessary.
TXP Builders – finely-crafted code, design and txp
Offline
Re: [Solved] REGEX headache
etc wrote #325226:
Why not just
<txp:title trim="/
|\(\d+\)/” />…@
Nice! Or if the Title also needs removing (which is what I’d understood):
<txp:title trim="/(.*?)@|\(\d+\)/" />
TXP Builders – finely-crafted code, design and txp
Offline
Re: [Solved] REGEX headache
For others if that can help:
For my project, I use the duplicate articles feature because the articles (products) are the same things (the only difference is the book format).
This REGEX serves me to format the article titles (with a line break for the author names) without all the mess. ;)
Last edited by Pat64 (2020-08-07 10:23:36)
Patrick.
Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.
Offline
Re: [Solved] REGEX headache
etc wrote #325226:
Why not just
<txp:title trim="/
|\(\d+\)/” />…@
Simple and perfect Oleg (as always).
The raison why: I need to add a line break into the titles (and you advice didn’t give me what I want : <h1>«Title» <br />First Name Last Name</h1>
Last edited by Pat64 (2020-08-07 10:30:02)
Patrick.
Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.
Offline
Re: [Solved] REGEX headache
Oleg’s method would work there too if you used txp:title twice. Something like:
<h1><txp:title trim="/@(.*?)/" /> <br> <txp:title trim="/(.*?)@|\s*\(\d+\)/" /></h1>
No idea which is better.
TXP Builders – finely-crafted code, design and txp
Offline
Re: [Solved] REGEX headache
Thank you lot both ;)
Patrick.
Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.
Offline
Pages: 1