Jump to content

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.

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.