Using Regular expression to search for a value but exlude that string from the results?
This is prob real开发者_JS百科ly simple, I'm new to regular expressions but say I wanted to find the 2 numbers preceding some characters. i.e "12 qty"
So I'm using \d\d.qty to bring back the match "12 qty" but I want to exclude the word qty?
I have tried using \d\d.qty*([^qty]*) but it doesn't work.
You need to use a positive look ahead, depends on which language of course:
(\d\d)(?=\sqty)
You could use (\d\d)(.qty)
so you get back
Array
(
[0] => Array
(
[0] => 12 qty
)
[1] => Array
(
[0] => 12
)
[2] => Array
(
[0] => qty
)
)
Now use second item of the array and you have, what you want
精彩评论