• 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
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

Reg ex help desired; should be simple, but...

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I guess regular expressions are just not my thing.

To give some quick background, I am writing an installer using IzPack (great open-source product). Our requirements for the installer entail making sure that some of the paths/directories selected by the user for various inputs do not have spaces (but will accept all other normal path characters). I can accomplish this using IzPack's built-in regular expression validator, but I can't seem to nail the reg ex. I've been trying online resources and my own Java program to test, fix, test again, etc...

My understanding of regular expressions is not great; I understand the basics (start and ending of pattern, etc.). I know that /s should be used as the pattern for finding whitespace.

For anyone willing to spend a few minutes to show me where I have gone wrong, again, I am trying to determine whether or not the test string matches/works with a regular expression that will allow basically all characters *minus* whitespace. This is solely to avoid a potential issue with Windows in which the installed application basically hates any space in the directory/path (pretty common for older Windows apps).

Here are some examples of what I have tried for the reg ex:

^[a-zA-Z0-9]*\s$

^[a-zA-Z0-9\w]*\s$ Comment: \w should allow all characters, no?

^[a-zA-Z0-9]*\s$

^[a-zA-Z0-9]*.\s$


And here are some test strings that should or should not work:

Good: /home/username
Good: C:\Users\username
Bad: C:\Program Files\My Program\
Good: /usr/jdk1.6.20/
Bad: C:\Program Files\JavaSoft\Java 1.6\

Thank you!!
 
Sheriff
Posts: 22504
122
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How about ^[^\s]+$ or its simpler form ^\S+$ ? [^\s] means anything but \s so anything but whitespace. That one is also known as \S.
 
Chris Simons
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh my...that works perfectly. I must remember to Keep It Simple (Stupid).

Thank you!
 
reply
    Bookmark Topic Watch Topic
  • New Topic