我有一些我需要解决的错误的MySQL条目.我试图在PHP中这样做.
我得到了什么:
a whole bunch of text with no numbers Entry #:
2439. a whole bunch of text Click here to blah blah blah
我想要的:
a whole bunch of text with no numbers Entry #:
2439 . a whole bunch of text
Click here to blah blah blah
我的PHP代码:
$fixed = preg_replace('/(.*)(\d*)(.*)(Click here.*)/i',"$1$2$3
$4",$originalData);
出于某种原因,这是我得到的:
a whole bunch of text with no numbers Entry #:
2439. a whole bunch of text
Click here to blah blah blah
2美元不是第二次给我这个数字.有人有主意吗?
这是因为第一场比赛是贪婪的:
鉴于此输入,这是每个部分匹配的内容:
a whole bunch of text with no numbers Entry #: 2439. a whole bunch of text Click here to blah blah blah (.*) // "a whole bunch of text with no numbers Entry #: 2439. a whole bunch of text " (\d*) // "" (0 or more numbers) (.*) // "" (0 or more characters)
你所要做的就是让第一场比赛变得非贪婪:
(.*?)(\d+)(.*)(Click here.*)
此外,由于您在字符串中定义正则表达式,因此需要转义斜杠:
"/(.*?)(\\d*) ...