• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

Pattern Matching

 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ,

I want to search for pattern like "ramesh@234.com" in some error log file which is tottally unindexed and unformatted.

The "ramesh@---.com" remains same where as integer varies(some times may be 4 digits also). I want to collect all those variables and store. Can you please help me how to set the pattern for that.

Thanks in advance..

 
Marshal
Posts: 76845
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That doesn't look correct. You are neither matching the @ nor the .com.
 
Sheriff
Posts: 22701
129
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your regex already is a good start. I only want to know why you escape the first r; you are not looking for ramesh but for a carriage return followed by amesh. Also, the \\w doesn't belong there. That matches [a-zA-Z_0-9].

What you want is this:
- literal ramesh
- literal @
- \\d 3 or 4 times
- literal .
- literal com

Paste that together and you get this: "ramesh@\\d{3,4}\\.com"

You may also want to replace that matcher.pattern() with matcher.group(). matcher.pattern() returns the Pattern object, matcher.group() returns the found result.
 
Ramesh Sunkara
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Rob thank you
it worked
 
Rob Spoor
Sheriff
Posts: 22701
129
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're welcome.
 
Ramesh Sunkara
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey I got an issue..

Here am not able to get pc107 and pc110.. i cant figure it out ?

can you please help me.

I set the pattern as "pc\\d{3,4}" in the above program.


This the file which I searched? The text i pasted here appear in one line in the text file


{'status': 'ready', 'state': 'started', 'details': {'etc:example:VPN+example.net+sliver+6187': {'status': 'ready', 'state': 'started', example: 'urn:publicid:IDN+emulab.net+node+pc160', 'error': ''},

'urn:example:example+example.net+example+6186': {'example': 'ready', 'state': 'started', 'component_urn': 'urn:example:IDN+example.net+node+pc107', 'error': ''}}
{'status': 'example', 'state': 'started', 'component_urn': 'urn:publicid:example+example+node+pc108', 'error': ''}}
{'status': 'rexampley', 'example': 'started', 'component_urn': 'urn:publicid:MSN+example+node+pc109', 'error': ''}}{'status': 'reexampleady', 'state': 'started', 'component_urn': 'urn:publicid:example+example+node+pc110',

'error': ''}}
 
Rob Spoor
Sheriff
Posts: 22701
129
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's because you are using an if statement to find. That means you only call find() once, and only will find the first match. Change "if (matcher.find())" into "while (matcher.find())" to loop through all matches per line.
 
Ramesh Sunkara
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks ROB for your valuable time.
 
Rob Spoor
Sheriff
Posts: 22701
129
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rob Prime wrote:You're welcome.

 
Barry's not gonna like this. Barry's not gonna like this one bit. What is Barry's deal with tiny ads?
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic