0

i have an xml file with a lots of data, but it also contains a list of ids which looks like this

<test test-id="014727">
<not-test not-test-id="11111">
<not-test not-test-id="22222">
<not-test not-test-id="3333">
<test test-id="019727">
<test test-id="013727">

So far I have searched for test-id which gives me a list of all numbers, but it doesn't filter out additional info.

Using a regex in sublime text, how can I get a list of all the numbers after test-id?

So from the example above I would have 3 lines of:

  1. 014727

  2. 019727

  3. 013727

MattDMo
  • 100,794
  • 21
  • 241
  • 231
  • cmd-f, test-id, opt-enter, right-arrow, right-arrow, right-arrow, opt-shift-right-arrow, cmd-c - all numbers have been copied to your clipboard – Mulan Jul 04 '16 at 15:45
  • Came here to read about inverted commas. Was disappointed to see quotation marks – Dave Jul 04 '16 at 15:47
  • 1
    @dave excuse my english :-( –  Jul 04 '16 at 15:47
  • @naomik is it different if i use a mac? –  Jul 04 '16 at 15:50
  • @dave it is not a duplicate as i have a lot of other info in there that has quotation marks that i wish to ignore –  Jul 04 '16 at 15:55
  • Do you know how regular expressions work? If so, it's easy as pie. If not, please read up on them, and it'll be easy as pie once you get the hang of it. – Nic Jul 04 '16 at 15:57
  • Press `control + H`..you can use as find `^.*?\stest-id="(\d+).*$` and replace with `$1` – rock321987 Jul 04 '16 at 16:11

2 Answers2

0

EDIT

Original question was edited to exclude <not-test not-test-id="11111"> nodes. Modify step 2 below to add a space () before test-id in the search query. The rest of the steps stay the same.


The following keystrokes are for use with Sublime on OS X. If someone wants to provide the Windows equivalent, that would be helpful.

  1. cmd - f to enter search mode
  2. type in the text test-id
  3. press opt - enter to match all results in the current file
  4. with each instance of test-id highlighted, move your cursor right 3 characters with 3 times
  5. press opt - shift - to select the entire word (number in this case)
  6. press cmd - c to copy the selected text to the clipboard
  7. move your caret anywhere you wish to paste the copied numbers and press cmd - v

enter image description here

In the gif above, I finish with

  1. cmd - a to select all text
  2. cmd - v to paste the copied numbers
Mulan
  • 129,518
  • 31
  • 228
  • 259
  • but if there are more than 3 results this will take a lot longer no? –  Jul 04 '16 at 15:59
  • Unless you have like 10,000 results it should be fine. Even if that's the case, it will still work; it will just be slow yes – Mulan Jul 04 '16 at 15:59
  • The whole point of doing it this way compared to using a regexp is that it's super quick to try these methods of text navigation/manipulation in sublime. Try it and see! – Mulan Jul 04 '16 at 16:00
  • This is only going to work if all your IDs have the same number of characters – Dave Jul 04 '16 at 16:19
  • 1
    @dave nope. That's why I chose `opt`-`shift`-`→` to select the whole word. Each number can be of varying length so long as the length is at least 1. – Mulan Jul 04 '16 at 16:22
0

This regular exp. will search for multiple test-id attribute, and list down the matches globally :

/(?:test-id=")([^"]*)(?:")/g
binariedMe
  • 4,309
  • 1
  • 18
  • 34