Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2020-08-06 05:36:59

Pat64
Plugin Author
From: France
Registered: 2005-12-12
Posts: 1,415
Website

[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

#2 2020-08-07 05:48:15

Pat64
Plugin Author
From: France
Registered: 2005-12-12
Posts: 1,415
Website

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

#3 2020-08-07 07:22:07

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 3,933
Website

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

#4 2020-08-07 10:02:46

Pat64
Plugin Author
From: France
Registered: 2005-12-12
Posts: 1,415
Website

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

#5 2020-08-07 10:09:25

Pat64
Plugin Author
From: France
Registered: 2005-12-12
Posts: 1,415
Website

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

#6 2020-08-07 10:12:42

etc
Developer
Registered: 2010-11-11
Posts: 3,855
Website

Re: [Solved] REGEX headache

Why not just

<txp:title trim="/@|\s*\(\d+\)/" />

Offline

#7 2020-08-07 10:15:52

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 3,933
Website

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

#8 2020-08-07 10:20:34

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 3,933
Website

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

#9 2020-08-07 10:22:14

Pat64
Plugin Author
From: France
Registered: 2005-12-12
Posts: 1,415
Website

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

#10 2020-08-07 10:29:24

Pat64
Plugin Author
From: France
Registered: 2005-12-12
Posts: 1,415
Website

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

Board footer

Powered by FluxBB