• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

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.
 
It sure was nice of your sister to lend us her car. Let's show our appreciation by sharing this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic