简体   繁体   English

如何在Java中查找所有未出现\\或未转义的$出现

[英]How to find all occurrences of $ which are not escaped or preceded by \ in java

Test Cases : 测试用例 :

  1. he is having $money 500 他有500美元的钱
  2. he is having \\$money 500 他有\\ $金钱500
  3. $ $
  4. \\$ \\ $

Matches should be the 1st & 3rd one, since 2nd & 4th already contains escaped "$". 匹配项应该是第1个和第3个,因为第2个和第4个已经包含转义的“ $”。

I tried - Pattern pattern=Pattern.compile("(^\\\\\\\\$)"); 我尝试过- Pattern pattern=Pattern.compile("(^\\\\\\\\$)"); but it doesn't match any. 但不匹配 Please help. 请帮忙。

(?<!\\)\$

You can try this.See demo. 您可以尝试一下。请参阅演示。

http://regex101.com/r/sU3fA2/34 http://regex101.com/r/sU3fA2/34

您可以在此处使用负向后查找来排除已经转义的$字符。

(?<!\\\\)\\$

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用Java替换所有出现的以特定模式开头的字符串 - Replace all occurrences of a string preceded by specific pattern using java 正则表达式(Java)查找所有以偶数个其他字符开头的字符 - Regex (Java) to find all characters preceded by an even number of other characters 如何在 Java 中查找和替换字符串中所有出现的子字符串? - How find and replace all occurrences of substring in string in Java? 如何使用Java和Rhino查找所有出现的Javascript函数 - How to find all the occurrences of a Javascript function using Java and Rhino Java正则表达式之间找到所有但最后一个字符没有前面或后面 - Java Regex Find All Between But Last Character Not Preceded Or Followed By 在Java中查找字符串中出现的所有子字符串 - Find all occurrences of substring in string in Java 试图在java中的Arraylist中查找所有出现的对象 - Trying to find all occurrences of an object in Arraylist, in java java 正则表达式:如何找到前面没有空格和逗号的实数 - java Regex: how to find real number not preceded by spaces and comma 如何在Java中查找映射中值的出现 - How to find the the occurrences of a value in a map in java Java中的正则表达式:查找[char1]的所有实例,但前提是它们前面没有[char2] - Regex in Java: find all instances of [char1] but only if they are not preceded by [char2]
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM