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

URL regEx- should not start with dot(.)

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Experts

I am using below regular expression in my application:
\b([whtpfs.]{3,5}(:\/\/)?[\w\-_]+\.[\w\-_]+[\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])\b

But the limitation with this regex is that, it accepts dot(.) at the beginning, which is a wrong behaviour.

So can anyone please help me in updating this regex so that it should not accept (.) at its start.

Thanks
Gokul.
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would just live with it. In fact, I would use a much simpler regex, or skip it altogether. You'll get validation when you go to construct the URL object anyway, so there's not much point in constructing your own validation regex, other than to weed out some blatantly wrong ones at the UI level, possibly saving a trip to the server side.

Did you create that one yourself or get it off the web? There are several schemes it won't allow (file and jdbc at least). Is this what you want?
 
Gokul Bharati
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jeff,

Thanks for the reply. The problem we are facing is that there are several scenarios where end user uses below patter of text in case notes :

c2900-universalk9-mz.SPA.151-3.T

We are parsing for URL in notes and converting them to hyperlink. So in this scenario, javascript will parse it and covert it to :

c2900-universalk9-mz .SPA.151-3.T

Here '.SPA.151-3.T' is getting converted into hyperlink.
 
No thanks. We have all the government we need. This tiny ad would like you to leave now:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic