Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Regex-What is a great online tool for regex?

Posted on 2011-03-13
12
Medium Priority
?
68 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +2
12 Comments
 
LVL 1

Expert Comment

by:TSSTJeff
ID: 35123219
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
ID: 35123321
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
ID: 35123416
as.*?\)
I think that will do what you need
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 1

Expert Comment

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

Author Comment

by:Myilu
ID: 35123516
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
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 35124178
@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 75

Accepted Solution

by:
käµfm³d   👽 earned 2000 total points
ID: 35124186
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
ID: 35124813
Im hoping this will do the trick
at.*?\)\r\n.*?\r\n
0
 
LVL 35

Expert Comment

by:Terry Woods
ID: 35125139
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
ID: 41624609
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
ID: 41624610
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 to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

by Batuhan Cetin Regular expression is a language that we use to edit a string or retrieve sub-strings that meets specific rules from a text. A regular expression can be applied to a set of string variables. There are many RegEx engines for u…
Do you hate spam? I do, and I am willing to bet you do as well. I often wonder, though, "if people hate spam so much, why do they still post their email addresses on the web?" I'm not talking about a plain-text posting here. I am referring to the fa…
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…

670 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