1

I have the following text file content:

<?php
//================ Versions ================
$applicatoinversion = '1.2.3.40';
$someothervariable = 'td11';

$dbversion = '2.3.1.4';

Other code here
?>

I need to replace everything EXCEPT the (application) version number with an empty string. So I can save the following file:

1.2.3.40

I'm not using a programmig language so I need to do it only with regular expression replace.

So far can match the version number:

(?<=\$applicatoinversion = \')(([0-9]\.){1,3}([0-9])+)(?=\';)

And managed to match everything before:

(.|\n)*(?=
(?<=\$applicatoinversion = \')(([0-9]\.){1,3}([0-9])+)(?=\';)
)

But I'm stuck. I cant match everything BEFORE and AFTER version number. Any gurus here?

Thanks in advance

Slava
  • 13
  • 3
  • better approach would be to get the version number from the file, and save it (replacing the file), than replacing the rest. I'm not sure how to do it, you provided no more details how do you apply the regex. – nothrow Sep 17 '11 at 18:25
  • @Yossarian As I've said, I need to do it regex. I apply the regex using GUI of FinalBuilder, so can't manipulate the file using any programming language. – Slava Sep 17 '11 at 18:31

1 Answers1

2

(?s).*applicatoinversion = '(([0-9]\.){1,3}([0-9])+)'.*

just replace all with the match from group 1

Ben
  • 13,297
  • 4
  • 47
  • 68
  • Without the \s only one line is replaced by $1, is there a workaround for this? – Slava Sep 17 '11 at 19:05
  • The second one does nothing !? Maybe adding flags isn't supported in FinalBuilder, is there any other syntax? – Slava Sep 17 '11 at 19:18
  • added a matcher for linebreaks – Ben Sep 17 '11 at 19:27
  • Theoretically its ok, but it causes FinalBuilder and Notepad++ to crash when executing... Sometimes with error message "Stack overflow" – Slava Sep 17 '11 at 19:39
  • Got it! you can set (?s) before your first expression. Its from http://www.pcre.org/pcre.txt, read INTERNAL OPTION SETTING chapter. You can edit your original answer. Thanks for your help!! – Slava Sep 17 '11 at 20:23