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.
Matching special tags
Moderator: General Moderators
- prometheuzz
- Forum Regular
- Posts: 779
- Joined: Fri Apr 04, 2008 5:51 am
Re: Matching special tags
This regex matches those tags:
Code: Select all
\[\w+]Re: Matching special tags
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:
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);- prometheuzz
- Forum Regular
- Posts: 779
- Joined: Fri Apr 04, 2008 5:51 am
Re: Matching special tags
You didn't wrap my suggested regex pattern with delimiters. I presume you know what regex delimiters are? If not, Google for it!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);
Re: Matching special tags
Ahhhhh /\[\w+]/ my bad
I really don't undestand this RegEx stuff.
Thank you.
I really don't undestand this RegEx stuff.
Thank you.
- prometheuzz
- Forum Regular
- Posts: 779
- Joined: Fri Apr 04, 2008 5:51 am
Re: Matching special tags
Well, if you're using them from time to time, I recommend learning them.socket1 wrote:Ahhhhh /\[\w+]/ my bad
I really don't undestand this RegEx stuff.
Thank you.
You're welcome, of course.