Simple placeholder extraction regex

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Simple placeholder extraction regex

Post by alex.barylski »

I have the following:

Code: Select all

'#\{\%MANUAL_([0-9]+)\%\}#'
I need to extract placeholders of the type {%MANUAL_#####%}

Where ##### is any number between 1 and the limit of an integer, so it should be arbitrary, but always numbers.

The above regex is pretty simple but I figured I would post something incase I missed a caveat.

Cheers,
Alex
User avatar
prometheuzz
Forum Regular
Posts: 779
Joined: Fri Apr 04, 2008 5:51 am

Re: Simple placeholder extraction regex

Post by prometheuzz »

Nope, you haven't missed anything. It'll work as you expect it to.

The only thing is that you escape characters that don't need escaping ('%' and '}' are no meta characters), although it does not hurt to do so.

This will do the same:

Code: Select all

'#\{%MANUAL_([0-9]+)%}#'
Post Reply