Java – understanding regex if then statements

So I'm not sure I understand how this works

This is what I think is the format of the if / then / else option built in my regular expression engine:

?(condition)if regex|else regex

I want it to capture the string from a specific location only when it exists in some part of JavaScript Because this is how I think it works after a lot of research, I tried some variants of these codes, but they all ended up like this

((?^view_large$)Tables-137(.*?)search.htm)

Also relevant: I'm using a Java based application with regular expression search to extract the data I need, so I can't write if statements in Java, which will be my preferred method It's painful to have to do this, but I have no choice at the moment I'm trying to get them to allow java code functionality instead of pure regular expressions for more options

In short, is there an if / then option in the regex, and if so, how does it format what I want to do?

Edit: the string I want to be "if condition" is as follows: if view_ If the large string exists and is not null, the exact string 500 / (. *?) captured in the catch all group I use is captured

Solution

There are no conditions in Java regexp, but you can simulate them by writing two expressions containing mutually exclusive look behind structures, as follows:

((?<=if )then)|((?<!if )end)

When the current face has "if", the expression will match "then"; If there is no "if", it will match "end"

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>