What is "/[a-z]/" in js?? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

What is "/[a-z]/" in js??

12th Jun 2018, 11:13 PM
Sina
Sina - avatar
11 Answers
0
Sina Dont worry... Read they and if you dont understand something ask
13th Jun 2018, 12:27 AM
KrOW
KrOW - avatar
+ 6
I don 't know much about javascript but this seems to work: function a(){ var x = document.getElementById("in") if(/[a-b]/g.exec(x.value) != null){ alert("you enterd s.th between a-b") } }
13th Jun 2018, 4:59 AM
Paul
Paul - avatar
+ 3
Its an regex (regular expression) object that allow you to define a pattern (in this case an character from a to z lowercase) https://www.w3schools.com/Jsref/jsref_obj_regexp.asp
12th Jun 2018, 11:22 PM
KrOW
KrOW - avatar
+ 2
Thank you so much
12th Jun 2018, 11:51 PM
Sina
Sina - avatar
+ 2
I saw the w3schools examples could you plz write for me more e.g??
12th Jun 2018, 11:52 PM
Sina
Sina - avatar
+ 2
Can you write a code with both of them plz? if you could thanks
13th Jun 2018, 12:01 AM
Sina
Sina - avatar
+ 2
Sina You have to be more clear on what you want get... If you want check if a string contain the pattern "s.th" (without quotes) you can do it with String.indexOf method also while with pattern you have to make your function "a" like: function a(){ var x = document.getElementById("in").value if( /s\.th/.test(x)){ alert("you enterd s.th between a-b") } } Note that a String ITS DIFFERENT from a RegExpr: "I am a string" /I am a RegExpr/ Note start/end delimitator... Futhermore i have posted links because explain RegExpr its not simple above all in a comment... Please read these resources and post if you dont understand some concept
13th Jun 2018, 8:22 AM
KrOW
KrOW - avatar
+ 1
I'm so sorry becuse I saw your links now
13th Jun 2018, 12:24 AM
Sina
Sina - avatar
+ 1
How can I make s.th like this that works true https://code.sololearn.com/WW92AUsdxu4z/?ref=app
13th Jun 2018, 12:40 AM
Sina
Sina - avatar
0
# Below describe a pattern that atary with an lowecase alpha letter and follow least one alpha numeric (lowercase or uppercase) or underscore /^[a-z][a-zA-Z0-9_]+/ # Below describe a pattern that must match or "i am" or "you are" followed by " good" /(i am|you are) good/ https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
12th Jun 2018, 11:59 PM
KrOW
KrOW - avatar
0
Sorry but what you dont understand? I have posted two links for make you read futhermore and while i can post other example i think that online resources make this much better than me
13th Jun 2018, 12:13 AM
KrOW
KrOW - avatar