-2

hello this is my string

line('hello this is my \'first\' line')
line('hello this is my \'second\' line')
line('hello this is my \'third\' line')
line('hello this is my last line')

i want to use regex and get something like this

hello this is my \'first\' line
hello this is my \'second\' line
hello this is my \'third\' line
hello this is my last line

i am using this regex

line[(][']([^']*)['][)]

this regex just can get the last line because in each other lines ' ' exists. what should i do on this regex to get all line like result that i want?

Just please edit ([^']*) i just want to use this. (using start)

MyJustWorking
  • 117
  • 2
  • 8
  • if you are reading line wise, then it could have been done with (liitle modification) what I told yesterday – rock321987 Apr 16 '16 at 07:21
  • You need a part of [this solution](http://stackoverflow.com/questions/36597386/match-c-strings-and-string-literals-using-regex-in-python/36602277#36602277). See [this regex](https://regex101.com/r/pW8sT9/1) – Wiktor Stribiżew Apr 16 '16 at 07:25
  • @WiktorStribiżew also the comment you gave here :- (http://stackoverflow.com/questions/36646907/how-to-match-operator-separated-strings-in-sublime-package-development-yaml-tmla#comment60887421_36646907) with link (regex101.com/r/pC5wN5/2) – rock321987 Apr 16 '16 at 07:27
  • @rock321987: Yeah, too many almost-dupes. – Wiktor Stribiżew Apr 16 '16 at 07:28
  • @MyJustWorking Did you have a chance to try `"~line\\('[^'\\\\]*(?:\\\\.[^'\\\\]*)*'\\)~"`? – Wiktor Stribiżew Apr 16 '16 at 14:12

2 Answers2

0

Try this:

preg_match("/line\('(.*)'\)/", $string, $output_array);

http://www.phpliveregex.com/p/fmb

Edit.... preg_match_all("/line('([^']*)')/", $input_lines, $output_array);

http://www.phpliveregex.com/p/fmj

Andreas
  • 23,610
  • 6
  • 30
  • 62
  • Just please edit ([^']*) i just want to use this. (using start) – MyJustWorking Apr 16 '16 at 09:22
  • @MyJustWorking So you downvoted me because I did not see and understand your edit? Seriously?? Well now that you know how the comment function works, use that instead of downvoting. I will update my answer now with what I think you want. – Andreas Apr 16 '16 at 09:40
  • Ok. Sorry I missunderstod you. – Andreas Apr 16 '16 at 11:15
  • Your last edit just get last line ! did you check it? – MyJustWorking Apr 16 '16 at 14:20
  • @MyJustWorking Yes I did check it. It didn't work. And the reason is the ^. That sign means start of line. I can't use that in the middle of the pattern. What is wrong with the pattern I suggested first? – Andreas Apr 16 '16 at 16:01
  • ^ can be used if it's used as R.K's answer, at the start of the pattern and before line. – Andreas Apr 16 '16 at 16:02
-1

Use this regular expression:

 ^line[\(][\'](.*)[\'][\)]$