Jump to content

Preg Match Condition


shivam0101

Recommended Posts

Hello,

 

$line = "01 This is a sentence COND This is another sentence 10 P This is final sentence";

preg_match('/\bCOND\b.*(\d+) P\b/', trim($line), $matches)

 

print_r($matches[1])

prints 10

 

I want String "WR" in place of P.  I changed WR with P without any luck.  Can some one tell me what change has to be done?

 

I also want to know what's the meaning of P\b/',  mean?

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/207456-preg-match-condition/
Share on other sites

I want String "WR" in place of P.

 

What does that mean? Do you want to replace "P" with "WR" in the string or do you have a different string that uses "WR" insterad of "P" and you need the number in that string?

 

I also want to know what's the meaning of P\b/',  mean?

The space and "P" is trying to match those characters. The "\b" matches a word boundry such as a space, tab, period, etc. The "/" is the closing delimited for the expression.

 

Try giving a better explanation of what you are trying to achieve.

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.