1

I need to match and work with the following text

... and the start date is [startDate]|(D jS M Y g:iA).

The match should return any characters between the () brackets after [startDate]| (in this case D jS M Y g:iA), but should be dynamic so that it matches anything after the [ ]|. Ie should also work with the tag [otherDate]|(D jS M Y)

I've tried using positive look aheads, but haven't been able to get the result I need.

5
  • [[^[]]+]\|((.*?)(?=)) Commented Mar 1, 2019 at 23:41
  • How does your current code look like? Commented Mar 1, 2019 at 23:57
  • Is this a template language? It looks like it, but I don't recognize what it is specifically. Just curious Commented Mar 2, 2019 at 0:13
  • Not a templating language, but to solve the problem of allowing users a high degree of flexibility with date formatting, I drew inspiration from Phalcon Volt which I believe is heavily inspired by twig Commented Mar 2, 2019 at 0:19
  • @Don'tPanic - thats an interesting comment, as a long time project of mine is to create a template languages (i've written 3, but no like this). The idea is to use a lexer to parse the template then turn it into an actual PHP class. I'd be willing to discuss it more if your interested in it. Commented Mar 2, 2019 at 3:04

2 Answers 2

2

A pattern like the following will capture the part between the parentheses:

\[[^\]]*\]\|\(([^\)]*)\)

The first part matches an open bracket followed by 0 or more non-closing brackets and finally a closing bracket:

\[[^\]]*\]

And the rest is similar.

Perhaps try it at https://regex101.com/.

Sign up to request clarification or add additional context in comments.

Comments

-1
\[startDate\]\|\((.*)\).+

or without required "." on end:

\[startDate\]\|\((.*)\)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.