Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 72
  • Last Modified:

Regex-What is a great online tool for regex?

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
Myilu
Asked:
Myilu
  • 4
  • 2
  • 2
  • +2
1 Solution
 
TSSTJeffCommented:
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
 
MyiluAuthor Commented:
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
 
TSSTJeffCommented:
as.*?\)
I think that will do what you need
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
TSSTJeffCommented:
if you can send me a little more of the text Ill make sure it works for you
0
 
MyiluAuthor Commented:
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
 
käµfm³d 👽Commented:
@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
 
käµfm³d 👽Commented:
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
 
TSSTJeffCommented:
Im hoping this will do the trick
at.*?\)\r\n.*?\r\n
0
 
Terry WoodsIT GuruCommented:
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
 
EE_AutoDeleterCommented:
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
 
Terry WoodsIT GuruCommented:
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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 4
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now