开发者

How to write java.Replace regex expression?

开发者 https://www.devze.com 2023-04-05 21:49 出处:网络
I am trying to write a regex expression to replace the following in a space delimited file The file has:

I am trying to write a regex expression to replace the following in a space delimited file

The file has:

WORD WORD C F F ANOTHER WORD

ANOTHER WORD D H F ANOTHER ANOTHER

I am trying to get the expression to capture开发者_如何学JAVA the LAST F between F F and H F.

I wrote this expression but it doesn't process correctly in JAVA.

\\(\\(?:[a-z][a-z0-9_]*\\)\\)(\\s+)(F)(\\s+)

Can anyone help out? I'm trying to use this with String.ReplaceALL.

Thanks.


((?:[a-z][a-z0-9_]+))(\\s+)(F)(\\s+)

This is the translation of what you have that is a valid regex.


How about this one :

\\b(F)\\b(?!\\s+\\bF\\b)

looking for standalone F not followed by another standalone F


This one matches such strings. But how do you replace?

"^.* F ([^ ]*|[ F])*$"
0

精彩评论

暂无评论...
验证码 换一张
取 消