Solved

Regex-What is a great online tool for regex?

Posted on 2011-03-13
12
39 Views
Last Modified: 2016-05-30
I have the following text and need to come up with a Regex which matches the stackTrace starting with Exception:
bllaaaahblalllaa
Exception in thread "main" Java.lang.NullpointerException
at Text.SetValue(Text.Java:15)
at Text.Main(Text.java:8)
dflkkjweriuwrewopoew
erewkjwehrjwehwhrwow

So the output should be:

Exception in thread "main" Java.lang.NullpointerException
at Text.SetValue(Text.Java:15)
at Text.Main(Text.java:8)
0
Comment
Question by:Myilu
  • 4
  • 2
  • 2
  • +2
12 Comments
 
LVL 1

Expert Comment

by:TSSTJeff
Comment Utility
Expresso is the nicest regex I have used, however if you dont know regular expressions it will be a challange.
I dont think what you really need here is a regex but a simple application that will do a replacement for you.
but if you really want to use a regex then
you would want to pick out your values from the string text
at(?<Type>.*?)\((?<Message>.*?)\)
which would give you 2 values per item
type=Text.setvalue
message=text.java : 15
and type=text.main
and message= text.java:8
this you would need to put into an application to modify your text
0
 

Author Comment

by:Myilu
Comment Utility
i'm not sure you understood my questions.
I do not want to replace  any text or strings, i just need to multiline selection of Strings or text :
   Starting with a line which has the word beginning as  Exception and ends with a line which ends with  right paranthesis )

To give a better or concrete example, i want to capture from console only Stacktrace which has the above pattern.
0
 
LVL 1

Expert Comment

by:TSSTJeff
Comment Utility
as.*?\)
I think that will do what you need
0
 
LVL 1

Expert Comment

by:TSSTJeff
Comment Utility
if you can send me a little more of the text Ill make sure it works for you
0
 

Author Comment

by:Myilu
Comment Utility
WARNIG: Log Configuration Not Found
WARNING: (200)  String val in Text.java not intialized
Exception in thread "main" Java.lang.NullpointerException
at Text.SetValue(Text.Java:15)
at Text.Main(Text.java:8)
dflkkjweriuwrewopoew
erewkjwehrjwehwhrwow

The output should be:
Exception in thread "main" Java.lang.NullpointerException
at Text.SetValue(Text.Java:15)
at Text.Main(Text.java:8)
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 74

Expert Comment

by:käµfm³d 👽
Comment Utility
@TSSTJeff

>>  Expresso is the nicest regex I have used, however if you dont know regular expressions it will be a challange.

But it breaks down the meaning of the regex for you...   how hard could it be   = )

On a serious note, one thing to watch out for, though, is that Expresso uses the .NET regex engine, so it may use syntax different than the target language.



@Myilu

Try this out:
Pattern p = Pattern.compile("Exception.*\\s+(?:at .*\\s+)*");
Matcher m = p.matcher(target_string);

if (m.find()) {
    System.out.println(m.group());
}

Open in new window

0
 
LVL 74

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
Comment Utility
I made an assumption that this was going to be in Java. If it's not, you should be able to pull out the pattern above. The only change I believe will be required is to change the double backslashes to single backslashes.

i.e.

Exception.*\s+(?:at .*\s+)*

Open in new window

0
 
LVL 1

Expert Comment

by:TSSTJeff
Comment Utility
Im hoping this will do the trick
at.*?\)\r\n.*?\r\n
0
 
LVL 35

Expert Comment

by:Terry Woods
Comment Utility
kaufmed's solution works for me (and looks fairly robust too) - results can be viewed here at www.myregextester.com:
http://www.myregextester.com/?r=c00db15d
0
 

Expert Comment

by:EE_AutoDeleter
Comment Utility
I've requested that this question be deleted for the following reason:

                           
No comment has been added to this question in more than 21 days, so it is now classified as abandoned and is now flagged for deletion.


If there is a valid solution, please OBJECT and indicate the comments that are, or would otherwise lead to, a solution.


Use the specific format https:#axxxxxxxx for comment ID(s).


Also, please don't object simply because the author did not respond to your comment. While we understand this is frustrating, unfortunately we cannot force the author to return to the question. Unless you feel you have presented a valid, verifiable solution we'll simply delete the question.


Experts-Exchange Auto Deleter
0
 
LVL 35

Expert Comment

by:Terry Woods
Comment Utility
I recommend Kaufmed's answer #a35124186 be accepted as the solution. I verified it at the time and commented that it worked.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I have been reconstructing a PHP-based application that has grown into a full blown interface system over the last ten years by a developer that has now gone into business for himself building websites. I am not incredibly fond of writing PHP code o…
As most anyone who uses or has come across them can attest to, regular expressions (regex) are a complicated bit of magic. Packed so succinctly within their cryptic syntax lies a great deal of power. It's not the "take over the world" kind of power,…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now