I have HTML code like this:
<div class="inside">
<h2>Some text</h2>
Lorem Ipsum:<br />
[423A18K5][R68A18K5]
</div>
<div class="inside2">
<h2>Some other text</h2>
Lorem Ipsum:<br />
[9903A1K5][P095GR31]
</div>
What i need to do: i must select all codes between [ and ] with jQuery (and to pass them to ajax later).
NOTE: Instead of [] i can use some other symbols, but i cant use HTML tags.
Do you have any sugestions?
Not sure if all of the divs you’re trying to grab the data from has a common class or if they’re all unique as in your example. Also you give a very specific format for the contents of the div above. I.e.:
The code below works assuming that what you grab is in the same format. Basically it selects the div you want, gets the text inside, then drops leading or ending spaces, drops anything before the first ‘[‘, then gets rid of the first [ and last ], then creates the array, splitting on ‘][‘.
The regex could probably be cleaned up a bit, but it’s simple and it works.