Jump to content

Help with regex


ShaolinF

Recommended Posts

[] means a class, or posible options [abc] means a or b or c

 

so....your telling regex to match not match alot of stuff....

anyway what you want is:

 

(href="(.*?)")

 

that should work fine (as your entire expression, you dont need / / at the start and the end)

 

the data between quotes will be at result_array[1] btw

 

and the * is greedy, it matches any character AS MUCH AS IT CAN you want lazy to match it as little as posible (up until the next quote) otherwise it would match for example

 

href="stuff" more "stuff" "doo" "foo" "bar"

 

greedy regex matches:

stuff" more "stuff" "doo" "foo" "bar

 

Lazy matches:

stuff

 

the *? makes it 0 or more matches - but as little as posible.

 

Link to comment
https://forums.phpfreaks.com/topic/211440-help-with-regex/#findComment-1102421
Share on other sites

[] means a class, or posible options [abc] means a or b or c

 

so....your telling regex to match not match alot of stuff....

anyway what you want is:

 

(href="(.*?)")

 

that should work fine (as your entire expression, you dont need / / at the start and the end)

 

the data between quotes will be at result_array[1] btw

 

and the * is greedy, it matches any character AS MUCH AS IT CAN you want lazy to match it as little as posible (up until the next quote) otherwise it would match for example

 

href="stuff" more "stuff" "doo" "foo" "bar"

 

greedy regex matches:

stuff" more "stuff" "doo" "foo" "bar

 

Lazy matches:

stuff

 

the *? makes it 0 or more matches - but as little as posible.

Thanks - That does work but what Im trying to do is remove everything other than the href="test.htm" bit. How would I do that ? The only way I can think of doing this is using something like [^(expression here)] but that will match on a per letter basis.
Link to comment
https://forums.phpfreaks.com/topic/211440-help-with-regex/#findComment-1102433
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.