Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #31802

Re: check if string has non-word characters

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!news.swapon.de!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail
From Eric Sosman <esosman@comcast-dot-net.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: check if string has non-word characters
Date Tue, 16 Jun 2015 11:41:46 -0400
Organization A noiseless patient Spider
Lines 27
Message-ID <mlpg1e$h7n$1@dont-email.me> (permalink)
References <471b79ac-8ba1-40d4-8630-e75a8ca20abe@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=windows-1252; format=flowed
Content-Transfer-Encoding 7bit
Injection-Date Tue, 16 Jun 2015 15:40:30 +0000 (UTC)
Injection-Info mx02.eternal-september.org; posting-host="858a9d65d95f4ea4d355bd116aa2cdbf"; logging-data="17655"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/djgtpvqgJmUYWA3bjvV2W"
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0
In-Reply-To <471b79ac-8ba1-40d4-8630-e75a8ca20abe@googlegroups.com>
Cancel-Lock sha1:RzZ1BHjuspg6QwpE4e1fOuw4rjs=
Xref csiph.com comp.lang.java.programmer:31802

Show key headers only | View raw


On 6/16/2015 10:20 AM, mike wrote:
> Hi,
>
> String is not allowed to contain non-word characters. However it is ok with:
>
> 1.  = in as long it is not in the end or beginning of string.
> 2.  , as long as it is at the end of the string.

     Just typed in, untested:

	Pattern pattern = Pattern.compile("\\w[\\w=]*[\\w,]");

This isn't quite perfect, as it insists on at least two characters
(it won't match "x", for instance, though it will match "xx" or "x,").
Also, it matches "x=,", which your description permits but which might
not be what you intended.

     What is the larger problem you're trying to solve?  There might
be a better way to tackle it than to try to get the whole job done
with one super-regex.  As an old-line Netscape developer said,

	Some people, when confronted with a problem, think "I know,
	I'll use regular expressions."  Now they have two problems.

-- 
esosman@comcast-dot-net.invalid
"Don't be afraid of work. Make work afraid of you." -- TLM

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

check if string has non-word characters mike <mikaelpetterson@hotmail.com> - 2015-06-16 07:20 -0700
  Re: check if string has non-word characters Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-06-16 11:41 -0400
  Re: check if string has non-word characters Marcel Mueller <news.5.maazl@spamgourmet.org> - 2015-06-16 18:42 +0200
  Re: check if string has non-word characters Robert Klemme <shortcutter@googlemail.com> - 2015-06-16 22:58 +0200
  Re: check if string has non-word characters Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2015-06-22 16:13 -0700

csiph-web