| Author |
Regex- How to negate a word match embedded within a Pattern
|
Abhi murali
Greenhorn
Joined: Jan 28, 2010
Posts: 11
|
|
Hi,
I have the following text :
Here "constant text" is guaranteed to be present,i.e. After the "REQUIRED TEXT" , "constant text" is always present.
Also the string "Abstract" is present in the location as provided.
What is the regex for extracting the text "REQUIRED TEXT" ?
In words, give everything that is present between "Abstract" and "constant text" ,but has no "Abstract" in between.
I tried this
for which I get the result "Abstract some2 text2 Abstract REQUIRED TEXT constant text"
Its fine even if I get the result "Abstract REQUIRED TEXT constant text" , I can clip "Abstract " and "constant text" from the beginning and end.
Any answers?
|
 |
Abhi murali
Greenhorn
Joined: Jan 28, 2010
Posts: 11
|
|
Still no reply?
Have i not expressed the problem statement well? Please let me know!
|
 |
Maneesh Godbole
Saloon Keeper
Joined: Jul 26, 2007
Posts: 8430
|
|
Abhi murali wrote:Still no reply?
PatienceIsAVirtue EaseUp
|
[Donate a pint, save a life!] [How to ask questions] [Onff-turn it on!]
|
 |
Alexander Sales
Ranch Hand
Joined: Feb 21, 2011
Posts: 89
|
|
i think a better approach to extract, is to use the 'split()' at the string
and then loop into it. That way you could branch statements and get the data you need.
|
OCPJP 6, OCEWCD Java EE 6
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
How about this:
Your original regex said to only disallow an "Abstract" directly after "Abstract". This one takes into account anything that goes between the two Abstracts. If you add some parentheses around the second .* you can also use matcher.group(1) to retrieve the value for REQUIRED TEXT:
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
Raymond Tong
Ranch Hand
Joined: Aug 15, 2010
Posts: 156
|
|
Alexander Sales wrote:i think a better approach to extract, is to use the 'split()' at the string
and then loop into it. That way you could branch statements and get the data you need.
a similar approach could use String.lastIndexOf()
|
 |
 |
|
|
subject: Regex- How to negate a word match embedded within a Pattern
|
|
|