如果比赛是在字符串的开头,然后......在"。正则表达式"有条件的 [英] If Match is in the beginning of the String then... in ."Regex" Conditional

查看:141
本文介绍了如果比赛是在字符串的开头,然后......在"。正则表达式"有条件的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

))大家好,我想创建此语法的正则表达式条件((正则表达式),那么|?其他人),请一个正则表达式。 这是我的字符串...

)) Hi all, I would like to create a regEx Conditional of this syntax (?(regex)then|else) please a regex. This is my string...

cook, eat, write, play

目前即时通讯使用此正则表达式

currently Im using this Regex

(, )?write

......,并用,​​替换(没什么,只是将其删除)

... and replace it with "" (nothing, just delete it)

为了删除写字和逗号和空格大公可能或之前它可能不会出现。所以在应用我得到这个字符串...

in order to delete the "write word" and the "comma and space" thay may or may not appear before it. So after applied I get this string...

cook, eat, play

但如果我要删除的第一个字使用相同的正则表达式(,)在字符串中的煮?煮,我会得到这个尴尬的结果..

But If I would like to delete the first word "cook" in the string using the same Regex (, )?cook, I would get this awkward result...

, eat, write, play

所以,我想创建一个正则表达式的条件,可以查... 如果找到一个匹配的字符串的开头然后删除同样的,以前也有下面的逗号和空格,因此它给出结果...

So, I would like to create a Regex conditional that could check... If a Match is found at the beginning of the string then delete the same that before but also the following "comma and space" so it gives the result...

eat, write, play

我怎样才能创建条件?或者是任何其他更好的正则表达式来做到这一点? 请注意,使用宏自动化的工具,只允许我使用正则表达式,我不是编程,可以代替正则表达式的任何语言​​来替换文本即时通讯。请我只需要一个正则表达式的解决方案,即时通讯使用这个唯一的.NET正则表达式测试。的http://derekslager.com/blog/posts/2007/09/a-better-dotnet-regular-ex$p$pssion-tester.ashx

How can I create that conditional? or is any other better Regex to do that?? Please notice that Im using a Macro Automation tool that only allow me to Replace Text using Regex, Im not programming in any language that could replace the Regex. Please I need only a Regex solution, Im using this only .NET Regex tester. http://derekslager.com/blog/posts/2007/09/a-better-dotnet-regular-expression-tester.ashx

由于先进的。

推荐答案

我希望这是更复杂,但如果你必须有一个条件,
它的(前pressional): @(?(^)写的,[] | []写)

I wish it were more complicated but if you have to have a conditional,
its (expressional): @"(?(^)write,[ ]|,[ ]write)"

 (?( ^ )              # Conditional, is at BOS ? 
      write, [ ]          # Yes, this form
   |                     # else
      , [ ] write          # No, this form
 )                    # end conditional.

但是,没有实现同一个条件: @^写,[] | []写的

   ^ write , [ ]
|  
   , [ ] write

但是,也可能是更复杂的使用条件。 @(>(^)?)?:(?(1),[])(?,[])写入

 (?>( ^ )?)           # (1), Optional BOS, with atomic group
 (?: , [ ] )?         # Optional comma space for all 
 write                # 'write'
 (?(1) , [ ] )        # Conditional, if group 1 matched, 
                      # then match the space comma after
                      # otherwise, don't match anything else.

这篇关于如果比赛是在字符串的开头,然后......在"。正则表达式"有条件的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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