0

follow line

    This 
    <b>
    Strong
    </b>
    <u>
    Underline
    </u>
    Line.

must be match (see arrows)

    This --------------------> must match
    <b>
    Strong
    </b>
    <u>
    Underline
    </u>
    Line. -------------------> must match

but with this regexpression don't work

(>\n*(*.?)\n*)|(<\n*(*.?)\n*)

what's is wrong?

Andy Lester
  • 91,102
  • 13
  • 100
  • 152
Nico
  • 27
  • 1
  • 4
  • 2
    Please don't just show which lines have to match, but why they have to match. Given the information you provided, a regex like `^(This)|(Line.)` would be enough to match the both lines, but I'm sure it won't help you much. – Vince Sep 30 '13 at 13:45
  • And even given the regex you provided it's not possible to get an idea what you are trying to achieve here. The regex has a syntax-error and if we remove it, it matches all the `<` and `>` – Vince Sep 30 '13 at 13:46
  • **Don't use regular expressions to parse HTML. Use a proper HTML parsing module.** You cannot reliably parse HTML with regular expressions, and you will face sorrow and frustration down the road. As soon as the HTML changes from your expectations, your code will be broken. See http://htmlparsing.com/php or [this SO thread](http://stackoverflow.com/questions/3577641/how-do-you-parse-and-process-html-xml-in-php) for examples of how to properly parse HTML with PHP modules that have already been written, tested and debugged. – Andy Lester Sep 30 '13 at 14:09

2 Answers2

0

This RegEx is for finding the first and last line;

^(?:(?<![\f\n\r])(?:.*))(?=[\f\n\r])|^.*(?![\f\n\r])$

This can be split in two, first part;

^(?:(?<![\f\n\r])(?:.*))(?=[\f\n\r])

For finding the first line.

and second part;

^.*(?![\f\n\r])$

To find the last line.

Joran Den Houting
  • 3,149
  • 3
  • 21
  • 51
0

Try php's preg_match where $input_line is your string:

preg_match("/.*(\n)?/", $input_line, $output_array);
$firstMatch = output_array[0];
$lastMatch = end($output_array);

See demo: http://www.phpliveregex.com/p/1lp

Moob
  • 14,420
  • 1
  • 34
  • 47