Page 1 of 1
Matching special tags
Posted: Sat Jun 20, 2009 8:09 pm
by socket1
I've read quite a bit about RegEx and I still can't figure it out to a point where I can make things work.
This post is similar to my previous one a while ago
viewtopic.php?f=38&t=100032
I am trying to match all occurrences of something like [elementname] in a document.
It needs to be able to accept A-Z a-z 0-9 and _ characters of any length from 0 and greater.
Re: Matching special tags
Posted: Sun Jun 21, 2009 3:53 am
by prometheuzz
This regex matches those tags:
Re: Matching special tags
Posted: Sun Jun 21, 2009 9:45 am
by socket1
I tried using your regex and I get :
Warning: preg_match_all() [function.preg-match-all]: Delimiter must not be alphanumeric or backslash in F:\htdocs\scripts\run_code.php(4) : eval()'d code on line 1
this is what I used to test it:
Code: Select all
preg_match_all('\[\w+]', 'this is a [test] [string] full of[things]the regex should match', $matches);
print_r($matches);
Re: Matching special tags
Posted: Sun Jun 21, 2009 9:53 am
by prometheuzz
socket1 wrote:I tried using your regex and I get :
Warning: preg_match_all() [function.preg-match-all]: Delimiter must not be alphanumeric or backslash in F:\htdocs\scripts\run_code.php(4) : eval()'d code on line 1
this is what I used to test it:
Code: Select all
preg_match_all('\[\w+]', 'this is a [test] [string] full of[things]the regex should match', $matches);
print_r($matches);
You didn't wrap my suggested regex pattern with delimiters. I presume you know what regex delimiters are? If not, Google for it!
Re: Matching special tags
Posted: Sun Jun 21, 2009 10:00 am
by socket1
Ahhhhh /\[\w+]/ my bad
I really don't undestand this RegEx stuff.
Thank you.
Re: Matching special tags
Posted: Sun Jun 21, 2009 10:23 am
by prometheuzz
socket1 wrote:Ahhhhh /\[\w+]/ my bad
I really don't undestand this RegEx stuff.
Thank you.
Well, if you're using them from time to time, I recommend learning them.
You're welcome, of course.