How to get data between "_id =" and "&"?

How to process the line "7c23a12f0cffa6cf2fac0baf8eacf4c1" from the file. I am trying to get data between _id=

and&

example file:

4593733f4ab534f0001ecbe20000b3e9 / cgi-bin / rsspipes / dispatch Alternative = 10 = ECMINSTITUTE the Category & & the Type = News & _action the run = &? _Id = 7c23a12f0cffa6cf2fac0baf8eacf4c1 & _out the json = & _render the json = & = & _time dojo_preventCache = 1253389550099Z1f8wengine.pipes.yahoo.com: 8080rhttp: //ecminstitute.appspot.com/gMozilla/ 5.0 (Macintosh; U; Intel Mac OS X 10_4_11; en) AppleWebKit / 531.9 (KHTML, like Gecko) Version / 4.0.3 Safari / 531.910jdmm6t5aneif & b = 4 & d = zhJNm4hpYEL50eT2b_Zabr3mZKV2A1Am - shz.
+2


source to share


5 answers


id=([^&]*)&

      

Data between id = and and will be matched by the first (and only) group and then accessed via .group(1)

or similar depending on the language / regex library.



Edit: Modified +

to *

as suggested by Johannes RΓΆssel.

+4


source


Use a regular expression like this:

_id=([a-f0-9]+)&

      



The bracket defines the group that you can extract from the results.

+3


source


It is slightly more robust than some of the alternatives.

[&?] _ id = ([a-f0-9] +) (?: [&] | $)
[&?] # makes sure it isn't part of another parameter
_id=
(
  [a-f0-9]+ # at least one hexadecimal digit
)
(?:
  [&] # make sure there isn't some trailing data
|
  $   # might be at the end of the string
)

      

+3


source


I would use

perl -ne 'm/[&?]_id=([^&]+)(&|$)/ && print $1;' [file]

      

where [file]

is the name of the file containing the data.

0


source


I would use the following (non-greedy) Perl regex:

/_id=(.*?)&/

      

0


source







All Articles