Page 1 of 1

Delimiter is in the string!

Posted: Wed Dec 14, 2005 7:31 am
by spacebiscuit
Hi,

I am trying to extract the date from a string with this regular expression:

Code: Select all

/\d{2}/\d{1,2}/\d{4}/
The problem is that part of the string is the forward slash '/' which is also the string delimiter (?). How do I search on this charcter without causing the error:

Unknown modifier '\'

Thanks in advance.....

Rob.

Posted: Wed Dec 14, 2005 8:49 am
by Skittlewidth
I'm no expert on Regex but I think part of your problem is this:

Code: Select all

/d{2}/d{1,2}/d{4}/
should be

Code: Select all

\d{2}\d{1,2}\d{4}
as "\d" is any single digit and \d{2} would be two digits.

You just have the wrong slashes.

How are you applying this to your string though? You may be implementing it slightly wrong as well.

Edit: agh! Stupid PHPBB stripped the backslashes from my original code example! (fixed by putting it in Code tags instead of PHP)

Posted: Wed Dec 14, 2005 9:29 am
by sheila
From "Regex CRASH Course! (Pt. 1)"
viewtopic.php?t=33147
To delimit a regex we start and end with the EXACT same character. The two standards are (but you can use most non-alphanumeric characters):
Code:

/pattern/
#pattern#