• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Reg Exp for @www.webinspect.hp.com

 
Greenhorn
Posts: 15
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,


String str="@www.webinspect.hp.com";

I need to use a reg exp pattern for detecting @www.webinspect.hp.com for str.

Can anybody help me what should be the regexp for this type of string please?
 
lowercase baba
Posts: 13091
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What have you tried?
 
author
Posts: 23958
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Another point is... if you are looklng for an exact string, you don't need regular expressions. There are methods of the string class that can check if a string contains a particular string value.

Henry
 
Nitin Singla
Greenhorn
Posts: 15
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi
thanks for the reply..

str="@www.webinspect.hp.com";

is one example.. i just need one regexp for checking strings containing values like the one above in str..
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Nitin Singla wrote:is one example.. i just need one regexp for checking strings containing values like the one above in str.


Then you need to explain precisely what you mean by "values like". In fact, it'll be a big help in working out the regex for yourself.

Winston
 
Nitin Singla
Greenhorn
Posts: 15
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I mean to say str can be like

str="@****.com" -- where * denotes A-Z, a-z

examples:
str="@www.abc.com";
str="@www.webinspect.hp.com";
str="@www.def.com";
............


I am new to java and I am learning but i need this regexp. Please help.
 
fred rosenberger
lowercase baba
Posts: 13091
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We ARE helping. What we don't do is just give out an answer.

It is still not clear what you mean. I THINK you mean:

a literal '@' symbol

some number of alphabetics (what is the lower and upper limit?)

followed by the literal ".com"

However, your examples contradict what you state:

"@****.com" -- where * denotes A-Z, a-z

The, your example "@www.webinspect.hp.com" contradicts this. You say a '*' is a alphabetic, but this example has a '.' in it, between "webinspect" and "hp".

At the very least, you should give it a shot, and post what you try here.
 
Nitin Singla
Greenhorn
Posts: 15
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for correcting me sir.
Let me write it very carefully this time:

Format for url:

str="@***.**.**.com"

Correct example is below:

str="@www.webinspect.hp.com";


I need a regexp for the above type of format. Can anybody help me out here?
Thanks in advance.
 
Sheriff
Posts: 17677
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So, tell us what you came up with after you have gone through some of the links found by this search: regex tutorial
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Nitin Singla wrote:Format for url:

str="@***.**.**.com"


Aha. So @www.abc.com does not match? (Above, you said it should match). Because @www.abc.com does not have two dots before the ".com".

The point is, you need to exactly specify the rules. Once you've done that, you can formulate it as a regular expression. It's not good enough to say "it should be more or less like this". Computers only do exactly what you tell them to do - they can't work with approximate rules.

Have you already looked up the syntax for regular expressions in Java? So, what is your best guess for a regular expression for your case?
 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
to help you to find the correct regular expression, I suggest you think that way:

"between the @ and the .com you need a string which consits of only characters (and numbers or special characters like _ ?) and dots. Furthermore, there should only be single dots
and no dot at the beginning or the end of the string".

However, there might be more conditions, depending on what exactly you want.

Hope that helps a bit!

Michael
 
Nitin Singla
Greenhorn
Posts: 15
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I come up with this :

@([\w-]+\.)+[\w-]*

Please correct me if I am going in wrong direction?
But I am just asking for a help.. not for any humilation for beginners in java...

thanks
 
Henry Wong
author
Posts: 23958
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Nitin Singla wrote:I come up with this :

@([\w-]+\.)+[\w-]*

Please correct me if I am going in wrong direction?
But I am just asking for a help.. not for any humilation for beginners in java...

thanks




There is a reason why we are being that exact, even to the point of being anal. And it is not for humiliation. The reason is, regular expressions needs to be exact. It is amazing how many situations are obvious to you, where it isn't to regular expressions.

Anyway, what happened when you ran that regex? Did it work for all test cases?

Henry
 
Michael Krimgen
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Nitin Singla wrote:I come up with this :

@([\w-]+\.)+[\w-]*

Please correct me if I am going in wrong direction?
But I am just asking for a help.. not for any humilation for beginners in java...

thanks



The [\w-]* seems to be redundand and you miss out the .com at the end?

@([\w-]+\.)+com
would be sufficient as the + sign means at least once.

Btw, aren't you missing the www. at the beginning?

 
Nitin Singla
Greenhorn
Posts: 15
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

@www[\.]([\w-]+\.)+com

is updated one.

Is there any suggestions?

 
Ranch Hand
Posts: 275
jQuery Eclipse IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you trying to validate an email address?
Apache commons validator is pretty good for it.
 
fred rosenberger
lowercase baba
Posts: 13091
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Nitin Singla wrote:
@www[\.]([\w-]+\.)+com

Is there any suggestions?


I have two suggestions:

1) TRY IT OUT against your test cases
2) tell us if it worked or not. If it doesn't work, tell us which cases don't work, and why you think it should.
 
Winston Gutkowski
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Aniruddh Joshi wrote:Are you trying to validate an email address?
Apache commons validator is pretty good for it.


Also, as was pointed out to me by Rob Spoor: javax.mail.InternetAddress.

Winston
 
Winston Gutkowski
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Nitin Singla wrote:@www[\.]([\w-]+\.)+com
is updated one.
Is there any suggestions?


Yes. Stop coding.

You're suffering from "beginnersitis" at the moment, by which I mean that you're trying to solve everything with Java code.
There is no point in simply bashing out possible regexes and asking "is this right?". The fact is, if you deal with this properly, you'll know when it's right.

You've plainly done a bit of research into regexes, so you know what they expect; so my advice:
1. TURN YOUR COMPUTER OFF.
2. Sit down with your "pseudo-pattern" of '@***.**.*****.com' and write down the exact rules for it. You have an idea what regexes expect, so do it in those terms if you want; but write it in English, not it 'regex'ese.
3. When (and only when), you've done that, turn your computer back on and test it.

I'm afraid there's no shortcut to good code. You have to understand a problem before you can solve it.

Winston
 
Is this the real life? Is this just fantasy? Is this a tiny ad?
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic