正则表达式 - 具有特殊字符,符号和空格字符的单词组 [英] Regex-group of words with special characters,symbols and space character

查看:225
本文介绍了正则表达式 - 具有特殊字符,符号和空格字符的单词组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

示例

$ s ='这是一个带有一些测试用例的示例字符串\ cite {author1,author2,author3}。

然后{另一个例子} \ citeauthor {author3,author4},最后

\citeP {author1} \ citesome text {author5} \ citesome text with [ 。] ${author6}和字符串在这里完成。;





Example
$s = 'This is a example string with some testing cases \cite{author1,author2,author3}.
Then {another example} \citeauthor{author3,author4} and finally
\citeP{author1} \citesome text{author5} \citesome text with[.]$"{author6}and string completes here.';


$output= preg_replace_callback('/\\\\(cite(?:\w+)?){([^}]*)}/', function($m) {
  return preg_replace('/([^,]+)(?:,|$)/' ,'<xref '. $m[1] . ' >$1</xref>', $m[2]); },
  $s);





输出:



这是一个带有一些测试用例的示例字符串< xref cite => author1< xref cite => author2< xref cite => author3。

然后{an其他示例}< xref citeauthor => author3< xref citeauthor => author4,最后

< xref citep => author1 \ citesome text {author5} \\带有[。] ${author6}的\\ citesome文本和字符串在这里完成。



预期输出:





Output:

This is a example string with some testing cases <xref cite="">author1<xref cite="">author2<xref cite="">author3.
Then {another example} <xref citeauthor="">author3<xref citeauthor="">author4 and finally
<xref citep="">author1 \citesome text{author5} \citesome text with[.]$"{author6}and string completes here.

Expected output:

This is a example string with some testing cases <xref cite >author1</xref><xref cite >author2</xref><xref cite >author3</xref>. 
Then {another example} <xref citeauthor >author3</xref><xref citeauthor >author4</xref> and finally
<xref citeP >author1</xref>  <xref citesome text>author5</xref> <xref citesome text with[.]$">author6</xref>and string completes here.





问题:

/\\\\(cite(?:\w+)?)

- 只得到一组单词。我需要得到小组什么是正则表达式

- only get group of words. I need to get group of words with space symbols special character everything. What would be the regex

推荐答案

s ='这是一个带有一些测试用例的示例字符串\ cite {author1,author2} ,author3}。

然后{另一个例子} \ citeauthor {author3,author4},最后是

\citeP {author1} \ citesome text {author5} \带有[。]
s = 'This is a example string with some testing cases \cite{author1,author2,author3}.
Then {another example} \citeauthor{author3,author4} and finally
\citeP{author1} \citesome text{author5} \citesome text with[.]


{author6}的字符串文字和字符串在这里完成。';





"{author6}and string completes here.';



output = preg_replace_callback(' / \\\\(引用(?:\ w +)?){([^}] *)} /',函数(
output= preg_replace_callback('/\\\\(cite(?:\w+)?){([^}]*)}/', function(


这篇关于正则表达式 - 具有特殊字符,符号和空格字符的单词组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆