Hello everyone make sure to stop by and introduce yourself and do check out our design and programming sections.
Visit the Den and get some free stuff!

You are not connected. Please login or register

RegExp topic (ask questions)

View previous topic View next topic Go down  Message [Page 1 of 1]

1RegExp topic (ask questions) Empty RegExp topic (ask questions) Wed Mar 04, 2015 2:57 pm

george

george

Admin
Admin
Do you use regular expressions and if so what do you use them for? It's been a while since I messed with any sort of javascript since I am learning PHP but I have learned in the past about regexp and I remember it being a tad confusing.

Code:

re = new RegExp("\d[0-9]1+");

If i'm not mistaken the regexp would now look for any digits with numbers 0-9 and it must contain 1 number. Of course since nothing is defined it won't do anything but this is generally how it works correct?  scratch

http://gareygraphics.com

2RegExp topic (ask questions) Empty Re: RegExp topic (ask questions) Thu Mar 05, 2015 3:33 pm

TheDeveloper

TheDeveloper

Moderator
Moderator
There are multiple ways to test this.

Here is the best example to me.

Code:
//number variable
var numbers = "abc1234";

Code:
numbers.match(/[0-9]{1}/);

This will return an array of the instances. Only return one since in curly we have 1 meaning at least one instance, we can change this as {1,} meaning 1 or more of. or {2,5} between 2 and 5 times matched.

return example : ["1"]

Code:
(/[0-9]{2,3}/).exec(numbers);

Same as above just different in order of appearance. And this will return

["123"]

Code:
(/[0-9]{1}/).test(numbers);

Now this is my best option in my opinion for regex. Its testing the clause and returns true or false the above returns true. Theres a lot of regex, and what's more difficult is that every language changes a bit of it. PHP is different than JS, and JS is different than C++. It's annoying lol

3RegExp topic (ask questions) Empty Re: RegExp topic (ask questions) Fri Mar 06, 2015 7:08 pm

george

george

Admin
Admin
Yes I find that with different languages they do things differently a lot and it does wind up being a confusing situation sometimes especially when you are working a lot in more than one language it gets confusing.

http://gareygraphics.com

Sponsored content


View previous topic View next topic Back to top  Message [Page 1 of 1]

Share this topic!

URL Direct
BBcode
HTML
RegExp topic (ask questions)

Similar topics

-

» Questions to ask clients?

Permissions in this forum:
You cannot reply to topics in this forum