Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

DOMString

Posted on 2013-12-05
4
Medium Priority
?
283 Views
Last Modified: 2013-12-09
Hello,
I'm at <link no-authoritative competing site deleted by COBOLdinosaur, Topic Advisor>  where I find this;
"<tag>asd</tag>".match(/<tag>[^<]+<\/tag>/);
Is understanding this expression part of knowing JQuery, or some other language?
Or is it a regular expression.  In particular this part [^<]
I have been wanted to get to learn jquery, but have not gotten to it.
thanks
0
Comment
Question by:chima
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 82

Assisted Solution

by:leakim971
leakim971 earned 400 total points
ID: 39698927
this is only javascript code

match use a regular expression :

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match

If it was jQuery you should see some $ or jQuery somewhere
0
 
LVL 9

Accepted Solution

by:
Derek Jensen earned 1600 total points
ID: 39703448
The regular expression matches, specifically, "tag" tags. First I'll explain what it's doing and then see if I can make it a bit more useful. Feel free to paste this code directly into your page--inside your <script> tags, of course. ;-)

// First, let's break it out so it's a little bit more readable.

var myHTML = "<tag>asd</tag>";
myHTML.match(/<tag>[^<]+<\/tag>/); // This line alone doesn't do anything useful
                                   // Let's see what it's doing:
var foundMatches = myHTML.match(/<tag>[^<]+<\/tag>/);
alert(foundMatches[0]);
/* Well that's not very useful; we already know it matches! 
But *how* do we know it matches...??

First let's take everything inside the delimiters (forward slashes) 
  and break them up into their "atomic" components:
<tag>      Look for: a string of chars that equals *specifically* "<tag>".
           Since this doesn't have any wildcards (* + ? .) it ends before 
           the opening bracket...
[^<]+      which looks for: 
               one or more string of chars (+) 
               that are NOT ("[^...]" equals "!=...") a less than (<) ...
<\/tag>    and finally find us another specific "<tag>" string of chars.

Well that's *still* not very useful! So let's see if we can fix that...
*/
myHTML = "<div ref='this may be text that we can't know beforehand' id='blah'>
There's some TEXT in here!!
</div>";
foundMatches = myHTML.match(/<[^>]+?>([^<]+?)<\/[^>]+?>/sig);
alert(foundMatches[1]);

/*Now* we're talking! So let's see how this one is different:
<          Simple, look for a less than...
[^>]+?     We already know what this one does...but why the "?"? 
           All that does is turn our '+' wildcard into a non-greedy form, 
           which will match as *little* text as possible 
           instead of as *much* text as possible...
>          then look for a greater than...
([^<]+?)   then same as above--but wait! What's the parentheses doing?? 
           All that says to do is store everything that's found by the regex 
           inside the parentheses in its own index when it returns 
           the found matches. Moving on...
<\/        now look for another less than, followed by a forward slash. 
           The backslash in front of the forward slash says,
               "This is Not my delimiter marking the end of the regex, 
               but a character to look for"...
[^>]+?     again, look for anything but greater than...
>          and finally look for a greater than.

Now we look outside of the delimiters at the trailing chars, s, i & g.
These are called switches, and they turn on or off certain functionality
that you may or may not want, depending on what you're looking for.
The first one, "s", says to wildcards to match any char *including newlines*!
This is off by default. The second one, "i", we don't actually need, but it's
very useful to know, and probably the most used switch in regexes,
and it turns off case sensitivity, or makes the regex 'case-Insensitive'
The last one we don't need either, since our string only contains one tag,
but it makes the regex match as many times as possible within the given string,
or, Globally.
*/

Open in new window

0
 

Author Closing Comment

by:chima
ID: 39706565
Thank you both. bigdogdman great explanation.
0
 
LVL 9

Expert Comment

by:Derek Jensen
ID: 39706652
Glad I could help. :-)
Happy regexing!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question