[英]Regex replace in PHP to getting a number or a range after some prefixes
I have some texts with reference to lawsuit pages (folhas "fl. or fls." in portuguese) that I need to replace those numbers for a link (tag a) with an URL like: 我有一些有关诉讼页面的文本(葡萄牙语中的“ fl。or fls。”),我需要用以下网址替换链接(标签a)的这些数字:
"localhost/mni/consultarFolhas/".$page_start."/".$page_end
Text examples: 文字示例:
As you can see some times they use plural (s) even for single pages but for multiple pages they normally use "/" to the separate the range. 如您所见,有时甚至对单个页面也使用复数,但是对于多个页面,通常使用“ /”来分隔范围。
I tried this Regex but it is still ineficiente to catch the situations described above: 我尝试了此正则表达式,但仍然不足以捕捉上述情况:
const REGEX_FOLHAS = '#^.*\bfls?\. (\d+).*$#m';
So is it possible to create a REGEX to get those situations and replace with a hyperlink like this? 那么是否可以创建一个REGEX来获取这些情况并替换为这样的超链接?
Nos termos das <a href='localhost/m-n-i/consultarFolhas/10/44/'> FLS 10/ 44 </a> estão
<a href='localhost/m-n-i/consultarFolhas/53/'>Fl. 53</a>: Considerando a manifestação do Estado, excluam-se os executados
Your regex is almost what you want but you forgot some patterns and modifiers: 正则表达式几乎是您想要的,但是您忘记了一些模式和修饰符:
m
flag too) m
标志) i
flag) i
标志) \\.
\\.
and following space characters optional: \\.? *
\\.? *
\\.? *
(?:\\/ *\\d+)?
(?:\\/ *\\d+)?
编写可选模式(?:\\/ *\\d+)?
Putting all together: 放在一起:
(?i)\bfls?\.? *(\d+)(?:(/) *(\d+))?
PHP code: PHP代码:
preg_replace('~(?i)\bfls?\.? *(\d+)(?:(/) *(\d+))?~', '<a href="localhost/m-n-i/consultarFolhas/$1$2$3">$0</a>');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.