regular expression to replace '<?' by '<?php' - regex

Hi i'm trying to find all occurences of '<?' in my php code. I use eclipse for this, and i tried to search for the folowing pattern: "<\?^[p]" in the hope this would return me all <? occrences, but not the <?php ones..
What's wrong about the regex? I thought I had figured out regular expressions, but it seams like i still have a long way to go :(

try this: <\?[^p]

I'm not familiar with Eclipse's regular expression language but I'd imagine you want this:
"<\?[^p]"
The difference is:
[^p] means any character apart from p
^[p] means the start of a new line followed by a p.
But you should check the manual for Eclipse to find out the exact regular expression syntax that Eclipse uses.

If all fails, you could use a trick with no regexes: replace your <?php occurrences with something else (like for example THE_PHP_TAG), then search for <?, then replace THE_PHP_TAG back to <?php.

Edited
From what I understand you want to change <? to <?php. Try replacing <\?(?!php) with <?php. (This will prevent <?php from turning into <?phpphp).

Related

Using RegEx with Alteryx to replace string

I have a simple issue: Using Alteryx, I want to take a string, match a certain pattern and return the matched pattern.
This is my current approach:
Regex_replace("CP:ConsumerProducts&Retail</td><td><strong><fontcl","[^\<]+","$1")
According to various sources and tools like regex101, the first matched sequence should be "CP:ConsumerProducts&Retail". However, Alteryx returns
<<<<
Alteryx uses the Perl RegEx Syntax (https://help.alteryx.com/2018.2/boost/syntax_perl.html), therefore, it should have no problem with the pattern itself.
I believe I am missing something obvious but I cannot figure it out.
I have received a reply through a different forum. A solution that works for me is to use the following pattern: ([^\<]+).*
You can try the following workflow:

VS Code, find/replace access find results in the replace field

I have phone numbers on my file and I would like to surround each of them with braces, so if I have this:
"+49-1111"
"+49-2222"
I would like to run a replace operation and to get this:
["+49-1111"]
["+49-2222"]
Is that possible with the current vs code find/replace action?
If it is a dup sorry but I could find any explanation anywhere.
Thanks
This is more relevant to regular expression.
Find ("\+\d{2}-\d{4}"), replace the occurrences with [$1]
Be sure to turn the "Use Regular Expression" switch on.

Regular Expression for recognizing files with following patterns az.4.0.0.119.tgz

I am trying to find a regular expression that will recognize files with the pattern as az.4.0.0.119.tgz. I have tried the regular expression below:
([a-z]+)[.][0-9]{0,3}[.][0-9]{0,3}[.][0-9]{0,3}[.]tgz
But, no luck. Can anyone please point me in the right direction.
Regards,
Shreyas
Better to use a simple regex like this:
^([a-z]+)\.(?:[0-9]+\.)+tgz$
You just forgot one number part:
([a-z]+)[.][0-9]{0,3}[.][0-9]{0,3}[.][0-9]{0,3}[.][0-9]{0,3}[.]tgz
or
([a-z]+)[.]([0-9]{0,3}[.]){4}tgz
Depending on where and how you use the regex, you might want to surround it in ^...$.
Your pattern has 4 chiffers group, your regexp only 3.

Transform an expression to another with regex for a replace

I need to replace a lot of strings in an application and I can do it with regex but I don't know how.
My current string is: {$str.LOREM} or {$str.LOREM_IPSUM}.
And the output desired is: <?php echo i18n::n('example.lorem');?> or <?php echo i18n::n('example.lorem_ipsum');?>.
UPDATE: Due to confussion in a answer: I want to do it with my IDE. I have like 500 different strings. Netbeans let me use regular expressions and I would like to find one that works with the above example. If possible if is not need to write all the 500 to change, it'll be beter. Thanks!
How I can do it?
If your string looks like that, you dont need regex, as that will be pretty slow. You can use the faster str_replace method for that.
Its as simple as:
$content = str_replace('{$str.LOREM}', i18n::n('example.lorem'), $content);
$content = str_replace('{$str.LOREM_IPSUM}',i18n::n('example.lorem_ipsum'),$content);

Find & replace with regular expressions in netbeans

I'm looking for a regular expression that can find and replace all the text "anytext" with "anything" in netbeans, some of the symbols also contain this text. I've done it a while back for a single file but now I want to change everything in my application & I'm struggling to get it right.
Just use find & replace to replace all instances of "anytext" with "anything". There is no difference between this and a regex find & replace, because there doesn't exist a pattern that can be easily exploited using regex. There is no difference in this case. Based on your comment, you still must manualy enter the word you want replaced and a word that will replace it.
I think you have misunderstood a bit what regular expressions are all about.
Were you looking for something like this? Where it wouldn't grab it inside word?
\banytext\b