List Info

Thread: newbie question: non numeric non whitespace value




newbie question: non numeric non whitespace value
country flaguser name
United States
2007-02-08 14:46:50
I want to detect whether the java String has any non-numeric
and non-
whitespace char. For example, "12 34" returns
false, "1234" returns
false, "12a3" returns true, "a 12 3"
returns true, etc. What's the
regex for that? Can I use [^0-9\s]? If not, what does it
mean?


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Regex" group.
To post to this group, send email to regexgooglegroups.com
To unsubscribe from this group, send email to
regex-unsubscribegooglegroups.com
For more options, visit this group at http://grou
ps-beta.google.com/group/regex
-~----------~----~----~----~------~----~------~--~---


Re: newbie question: non numeric non whitespace value
country flaguser name
United States
2007-02-10 19:40:21
D is the opposite of d, and S is the opposite of s. If
I
understand your requirement correctly, [^ds] should be the
same as
[DS]


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Regex" group.
To post to this group, send email to regexgooglegroups.com
To unsubscribe from this group, send email to
regex-unsubscribegooglegroups.com
For more options, visit this group at http://groups.go
ogle.com/group/regex
-~----------~----~----~----~------~----~------~--~---


Re: newbie question: non numeric non whitespace value
country flaguser name
United States
2007-02-11 11:33:12
your requirement for detecting

**any non-numeric AND non-whitespace char**

leads to evaluating ALL your sample strings as TRUE, b/c
every string
in the list

"12 34"
"1234"
"12a3"
"a 12 3"

is comprised of a series of non-numeric (D) and non-
whitespace (S)
char. For exampl, str "12 34" consists of 4 S
chars : 1234 and 1 D
char, i.e the whitespace. That evaluates the str as TRUE
according to
your requirement above. So there is a constradiction between
your
requirements and your anticipated flag (FALSE) for this
string.

U need to tweak your logic, restate the requirement/rules
for
validation, and make another run at this.


On Feb 8, 3:46 pm, "u...yahoo.com"
<u...yahoo.com> wrote:
> I want to detect whether the java String has any
non-numeric and non-
> whitespace char. For example, "12 34" returns
false, "1234" returns
> false, "12a3" returns true, "a 12
3" returns true, etc. What's the
> regex for that? Can I use [^0-9\s]? If not, what does
it mean?


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Regex" group.
To post to this group, send email to regexgooglegroups.com
To unsubscribe from this group, send email to
regex-unsubscribegooglegroups.com
For more options, visit this group at http://groups.go
ogle.com/group/regex
-~----------~----~----~----~------~----~------~--~---


Re: newbie question: non numeric non whitespace value
country flaguser name
United States
2007-02-12 00:25:04
On Feb 8, 3:46 pm, "u...yahoo.com"
<u...yahoo.com> wrote:
> I want to detect whether the java String has any
non-numeric and non-
> whitespace char. For example, "12 34" returns
false, "1234" returns
> false, "12a3" returns true, "a 12
3" returns true, etc. What's the
> regex for that? Can I use [^0-9\s]? If not, what does
it mean?

If these strings are standalone, then you might try the
lookahead
construct, i.e.:

  (?=.*[^\d\s])

I dont know Java though, in Perl, the regex a test code is
like:

bash ~$ echo '12 34
1234
12a3
a 12 3' | perl -lne 'print "true: $_"
if/(?=.*[^ds])/'

this prints:
____________
true: 12a3
true: a 12 3

Xicheng


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Regex" group.
To post to this group, send email to regexgooglegroups.com
To unsubscribe from this group, send email to
regex-unsubscribegooglegroups.com
For more options, visit this group at http://groups.go
ogle.com/group/regex
-~----------~----~----~----~------~----~------~--~---


Re: newbie question: non numeric non whitespace value
country flaguser name
United States
2007-02-12 00:40:31
On Feb 10, 8:40 pm, "SlideGuitar" <d...anthonynassar.com> wrote:
> D is the opposite of d, and S is the opposite of s.
If I
> understand your requirement correctly, [^ds] should
be the same as
> [DS]

Hi, Tony, I guess you had a small mistake in this post.
[DS] is not
the same as [^ds].  [DS] actually contains all the
characters(the
same as [Ss]), since 's' is a subset of 'D'. 

Best regards,
Xicheng


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Regex" group.
To post to this group, send email to regexgooglegroups.com
To unsubscribe from this group, send email to
regex-unsubscribegooglegroups.com
For more options, visit this group at http://groups.go
ogle.com/group/regex
-~----------~----~----~----~------~----~------~--~---


Re: newbie question: non numeric non whitespace value
country flaguser name
United States
2007-02-12 08:55:29
Quite right! [DS] is a union. That's definitely not what
we want. My
apologies; if I'm in a hurry, I shouldn't post.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Regex" group.
To post to this group, send email to regexgooglegroups.com
To unsubscribe from this group, send email to
regex-unsubscribegooglegroups.com
For more options, visit this group at http://groups.go
ogle.com/group/regex
-~----------~----~----~----~------~----~------~--~---


Re: newbie question: non numeric non whitespace value
country flaguser name
United States
2007-02-12 09:02:34
Your requirement is still not clear. Do you *want* the
string to
contain *only* numeric or whitespace characters, so the
first
character which is both *non-numeric* and *non-whitespace*
will
invalidate it? I assume there's a find() method; I'm not
going to look
up the relevant javadocs. If you can find [^ds] within the
input
string, then the string is invalid. Here I'm leaving out the
extra
slash to escape the slash character itself in a Java string
literal.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Regex" group.
To post to this group, send email to regexgooglegroups.com
To unsubscribe from this group, send email to
regex-unsubscribegooglegroups.com
For more options, visit this group at http://groups.go
ogle.com/group/regex
-~----------~----~----~----~------~----~------~--~---


Re: newbie question: non numeric non whitespace value
country flaguser name
United States
2007-02-12 10:57:17
On Feb 12, 10:02 am, "SlideGuitar" <d...anthonynassar.com> wrote:
> Your requirement is still not clear. Do you *want* the
string to
> contain *only* numeric or whitespace characters, so the
first
> character which is both *non-numeric* and
*non-whitespace* will
> invalidate it? I assume there's a find() method; I'm
not going to look
> up the relevant javadocs. If you can find [^ds]
within the input
> string, then the string is invalid. Here I'm leaving
out the extra
> slash to escape the slash character itself in a Java
string literal.

I guess the OP's logic is: given an input string,
   if it contains only numbers or whitespaces(like
^[ds]+$), then
return false
   otherwise, return true.

>From my understanding, it's kind of like a negation of
the regex ^[d
s]+$. so '12 34' and '1234' are false, coz there are only
numbers and
spaces in the string.  but '12a3' and 'a 12 3' are true
since 'a' is
neither a 'number' nor a 'whitespace'..

If the above is true, then I think, [^0-9\s] in the OP's
post is
actually proper and enough for this need. 

Regards,
Xicheng


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Regex" group.
To post to this group, send email to regexgooglegroups.com
To unsubscribe from this group, send email to
regex-unsubscribegooglegroups.com
For more options, visit this group at http://groups.go
ogle.com/group/regex
-~----------~----~----~----~------~----~------~--~---


[1-8]

about | contact  Other archives ( Real Estate discussion Medical topics )