Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pattern Matching Problem 1

Status
Not open for further replies.

jahjah

Technical User
Jan 23, 2003
32
GB
I cant seem to get the pattern matching for the search below to work - this is the command I am using which seems to be working fine with the another search/replace. Does anyone have a better way of searching for a line beginning with a letter and followed by 4 numbers????

$pattern2='/\b\w\d{4}\s/'; //search for M9999 at start of line
$replace2=$NEWQTY; //

$txt = preg_replace($pattern2,$replace2, $txt);
 
starting with M9999:

how about this:
$txt = preg_replace("^M9999",$replace2, $txt);




Known is handfull, Unknown is worldfull
 
try
Code:
1,$s/\w\d{4}/
This is the way how RE works in UNIX, so it will maybe help you.
 
jahjah,

Is it the literal 'M9999' or any combination of A1234 ?
If it's the literal then use what vbkris suggests.

The regular expression I wrote earlier should also work.
'/\b\w\d{4}\s/' if there's a space after the subject. If not, just remove the \s

 
The change will only occur with the 4 numbers, ie it could be one of the following:

M0100
M0500
M0300
M0100
M0010
M0001
M0070

the capital M will be constant.
 
jahjah,

All needed is to replace the \w with the literal 'M'.
Code:
$pattern = '/\sM\d{4}/';

Clear text:
\s Find one (1) whitespece character (lin break, space, tab etc.)
M the letter 'M'
\d{4} four digits
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top