Hello. In the .cpp source, you need to tear out all #define
, and since #define
can take several lines, I can not build the correct regexp. At the moment, this option (does not find if more than 3 lines):
#d.*?(?(?=\\\r?\n)(.*?\n.*?\n)|\n)+
Hello. In the .cpp source, you need to tear out all #define
, and since #define
can take several lines, I can not build the correct regexp. At the moment, this option (does not find if more than 3 lines):
#d.*?(?(?=\\\r?\n)(.*?\n.*?\n)|\n)+
I tried to take into account all the possible aspects of writing defines:
Similarly between # and define
Screen about what happened:
Regular expression itself:
$RE = <<< HEREDOC ^ # Π½Π°ΡΠ°Π»ΠΎ ΡΡΡΠΎΠΊΠΈ ΠΈΠ»ΠΈ ΡΠ΅ΠΊΡΡΠ° (?P<probel> (?: [ \\t] | # ΠΏΡΠΎΠ±Π΅Π»Ρ, ΡΠ°Π±ΡΠ»ΡΡΠΈΡ ΠΈΠ»ΠΈ \\\\ # ΠΎΠ±ΡΠ°ΡΠ½ΡΠΉ ΡΠ»ΡΡ, Π·Π° Π½ΠΈΠΌ \\r? # Π²ΠΎΠ·ΠΌΠΎΠΆΠ½ΠΎ \r \\n # ΠΈ \n )*+ ) [#] (?P>probel) # Ρ
ΠΎΡΡ ΡΠ°ΠΊΠ°Ρ ΡΡΡΠ»ΠΊΠ° ΠΈ Π½Π°Π·ΡΠ²Π°Π΅ΡΡΡ ΡΠ΅ΠΊΡΡΡΠΈΠ²Π½ΠΎΠΉ, ΡΠ΅ΠΊΡΡΡΠΈΠΈ ΡΠ°ΠΊΡΠΈΡΠ΅ΡΠΊΠΈ Π½Π΅Ρ define(?=[^a-z0-9_]|\$) # define ΡΠΏΡΠ°Π²Π° ΠΎΡ ΠΊΠΎΡΠΎΡΠΎΠ³ΠΎ Π½Π΅ ΡΠΈΠΌΠ²ΠΎΠ» ΠΈΠ»ΠΈ ΠΊΠΎΠ½Π΅Ρ ΡΡΡΠΎΠΊΠΈ # Π³ΡΠ°ΠΌΠΌΠ°ΡΠΈΠΊΠ° ΡΡΠ΅Π±ΡΠ΅Ρ ΡΡΠΎΡΠ½Π΅Π½ΠΈΡ (?: \\\\[^\\r\\n] | # ΡΡΠΎ-ΡΠΎ ΡΠΊΡΠ°Π½ΠΈΡΠΎΠ²Π°Π½Π½ΠΎΠ΅, Π½ΠΎ Π½Π΅ ΠΏΠ΅ΡΠ΅Π²ΠΎΠ΄Ρ ΡΡΡΠΎΠΊ, ΠΈΠ»ΠΈ \\\\\\r?\\n | # ΡΠΊΡΠ°Π½ΠΈΡΠΎΠ²Π°Π½Π½ΡΠΉ ΠΏΠ΅ΡΠ΅Π²ΠΎΠ΄ ΡΡΡΠΎΠΊΠΈ, ΠΈΠ»ΠΈ [^\\r\\n] # Π»ΡΠ±ΠΎΠΉ ΡΠΈΠΌΠ²ΠΎΠ» ΠΊΡΠΎΠΌΠ΅ ΠΏΠ΅ΡΠ΅Π²ΠΎΠ΄Π° ΡΡΡΠΎΠΊΠΈ )*+ \$ # ΠΊΠΎΠ½Π΅Ρ ΡΡΡΠΎΠΊΠΈ ΠΈΠ»ΠΈ ΡΠ΅ΠΊΡΡΠ° HEREDOC; echo preg_replace("/$RE/xum", "<span style='color:white;background-color:blue'>$0</span>", $text);
A live example on IDEone .
I will be glad to comment. I by the way do not know what could be to the right of define. I assume that this is anything but [a-z0-9_]
.
This question was answered on the stack .
For those who do not like to follow the links:
'(?m)^#define (?:.*\\\r?\n)*.*$'
I did not check it myself, they write what should work for constructions like
#define max(a,b) \ ({ typeof (a) _a = (a); \ typeof (b) _b = (b); \ _a > _b ? _a : _b; })
Nothing is impossible.
Atomic grouping, or Not a step back!
Source: https://ru.stackoverflow.com/questions/106340/
All Articles
(\\$^.*)
- jmu