Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

RegEx Differences in PHP and AHK


  • Please log in to reply
2 replies to this topic
TLM
  • Administrators
  • 3864 posts
  • Last active:
  • Joined: 21 Aug 2006
I'm pretty comfortable with RegEx in AHK and several testing environments suggested to me by PhiLho and majkinetor.

I'm trying to do a RegExReplace in PHP using preg_replace() however I can't seem to get the same result.
It essentially trims the end of off a varying breadcrumb result.
For instance in this example I'm trying to remove a line feed return and non word character.
Str =
(
<a class="headerNavigation" href="http://localhost/index.php?cPath=21_24">Products</a>
ยป
<a class="headerNavigation" href="http://localhost/info.php?cPath=21_24&products_id=28"></a>
</p>
)

; Testing Environment:
echo RegExReplace( str, ">\K\r\W(?=\r.*?pr)" ) ; Works!

; AHk
RegExReplace( str, ">\K`n\W(?=`n.*?pr)", "" ) ; Works!

; PHP
echo preg_replace( '/>\K\r\W(?=\r.*?pr)/', '', $str ); Fails!
I've tried several modifications including a non shorthand positive look-behind and different (*LF)(*CR)(*CRLF) combinations.

Anyone know how I can get this to work?

Thanks for any help as I know its not AHK related..

Posted Image

don't duplicate, iterate!


TLM
  • Administrators
  • 3864 posts
  • Last active:
  • Joined: 21 Aug 2006
Wow... Just tackled a cross browser compatible needle.
Something as simple as "/.*?n>(?=\w+)|</s.*/i"
to remove everything but the country in "<div id="g_icon"></div><SPAN>German</span>"
choked IE's SUPER non complaint variable. NEway got it working...

/<.*?>/g

SMFH@MS..

Posted Image

don't duplicate, iterate!


TLM
  • Administrators
  • 3864 posts
  • Last active:
  • Joined: 21 Aug 2006
NTS: Do not forget to escape forward slashes inside patterns /^.*?\/c/g

Posted Image

don't duplicate, iterate!