Oraclesqlnote

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

The character class [A-z] is probably not what you need.

Why?

The character class [A-z] matches some non-alphabetical characters like [, ] among
others.

JS fiddle link to prove this.

This W3school tutorial recommends it incorrectly.

If you need only lowercase letters use [a-z]


If you need only uppercase letters use [A-Z]
If you need both use: [a-zA-Z]

If you want to match a string if it has 2 letters followed by 3 digits anywhere in


the string, just remove the end anchor $ from your pattern:

[a-z]{2}[0-9]{3}
If you want to match a string if it has 2 letters followed by 3 digits and nothing
else use both start anchor ^ and end anchor $ as

^[a-z]{2}[0-9]{3}$

shareimprove this answer


edited Dec 2 '10 at 12:22
answered Dec 2 '10 at 11:40

codaddict
295k56399466

Hi, It was a string of exactly two a-z followed by three 0-9. Cheers. � Scott Brown
Dec 2 '10 at 11:45

The character class I'm using the the ' Find any character from uppercase A to
lowercase z' as found on w3schools.com/jsref/jsref_obj_regexp.asp. Is this not
recommended? � Scott Brown Dec 2 '10 at 12:03

@Scott: It is not recommended. Please see my updated answer. � codaddict Dec 2 '10
at 12:14

Ok, thanks for the update and explanation. � Scott Brown Dec 2 '10 at 12:22
add a comment
up vote
1
down vote
Alternatively you can use:

/\b([A-z]{2}[0-9]{3})\b/g
if your string contains multiple words and you are trying to match one word.

You might also like