Jump to content

Recommended Posts

I've read this thread

http://forums.phpfreaks.com/topic/12377-common-expressions/

 

I've tried to match my patter to extract the date from this

On:</td>
	  <td><strong>9/30/12</strong></td>

 

here is my expression

"#On:</td>\s*<td><strong>\s*<td><strong>(1-9){1,2}[\/](1-9){1,2}[\/](1-9){1,2}</strong></td></strong></td>#i"

 

it is not working for me, please help

Link to comment
https://forums.phpfreaks.com/topic/269471-simple-date-regex/
Share on other sites

Try this maybe?

'%On:</td>\s*<td><strong>\s*(\d){1,2}[/](\d){1,2}[/](\d){1,2}%i'

 

A couple things I noticed:

  • Your range is only 1-9 missing 0's (Mine is \d matching numerals)
    (Also it wasn't placed in a range modifier so it would have tried literally matching "1-9")
  • Your opening and closing <td> <strong> html elements are trying to match 2x (on both sides) as oppose to your initial test subject, in which the tags only appear once.

Edited by DarkerAngel
Link to comment
https://forums.phpfreaks.com/topic/269471-simple-date-regex/#findComment-1385240
Share on other sites

Nothing at all, simply put it's only a regex delimiter ( #, %, /, &, ~, ! ), I just normally go with the one RegexBuddy gives me ;D usually saves the "Opps, I'm using that in my expression" problem.

 

'%On:</td>\s*<td><strong>(\d{1,2})/(\d{1,2})/(\d{1,2})%i'

 

Few More Points I guess I missed when I posted previously:

  • For some reason I left the " / " in the [ ] range delimiter even though " / " is not a range
  • I had repetition modifiers outside the capture group resulting in a Last Case capture (in tester)
  • Had a whitespace search after the <strong> tag though it didn't seem to affect the tester

This one might work a little better, if not I might need to see more of what you're trying to match against since my tester is reporting it a valid match (as well as capture groups)

Link to comment
https://forums.phpfreaks.com/topic/269471-simple-date-regex/#findComment-1385279
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.