Find in Eclipse, what reg expression?
input <CFCOOKIE name="JOE" value="2">
<CFCOOKIE name="Bill" value="2000">, etc...
Replace in Eclipse, what reg expression?
output <CFCOOKIE name="Joe" value="2" httponly="yes" secure="Yes>
<CFCOOKIE name="Bill" value="2000" httponly="yes" secure="Yes>", etc.
Looking for reg expressions to do this work. Please help newbe. This is using menus in Eclipse--no language other than regular expressions needed. Btw, the original data like may have more than two properties. I need to insert httponly="yes" secure="Yes" before the final >
Asked
Active
Viewed 52 times
-2

CB1004
- 1
- 1
-
Do I understand correctly that you want to use the Search and Replace menu in eclipse to replace one string with another using regex? – Michael Kotzjan May 04 '21 at 07:58
-
1Yes. But, I want to use a regex in both the find and replace actions. – CB1004 May 04 '21 at 17:09
1 Answers
-1
First. You didn't specify a language. As you are a newbie and you said
Eclipse
I expect it to be Java, although I might be wrong.
The answer would be to use some sort of XML parsing function to just add the attributes and revert them to strings
or if you really insist on it a Regular Expression, your pattern would look something like this:
"(<CFCOOKIE name=\")(\w*?)(\" value=\"\d+\")>"
And to use it you would write:
String string = "<CFCOOKIE name=\"JOE\" value=\"2\">\n"
+ "<CFCOOKIE name=\"Bill\" value=\"2000\">";
String sub = "$1$2$3 httponly=\"yes\" secure=\"Yes\">";
Pattern pattern = Pattern.compile("(<CFCOOKIE name=\\\")(\\w*?)(\\\" value=\\\"\\d+\\\")>");
Matcher matcher = pattern.matcher(string);
String result = matcher.replaceAll(sub);
System.out.println("Result: " + result);
If you have to convert names to [A-Z][a-z] forms I would recommend reading about how to do that and incorporating this answer with mine.
As you stated in the comment, you want to use Eclipse built-in text replacer.
To replace like you want just use <(CFCOOKIE .*?)>
and replace it with <$1 httponly="yes" secure="Yes">
and that should work.

SkillGG
- 647
- 4
- 18
-
This is using menus in Eclipse--no language other than regular expressions needed. Btw, the original data like may have more than two properties. I need to insert httponly="yes" secure="Yes" before the final > – CB1004 May 04 '21 at 13:26
-
-
The suggestion does not work. What does <$1 mean? The changed result should be..
– CB1004 May 05 '21 at 19:17 -
`$1` means change into first capturing group. The thing that was captured inside `(CFCOOKIE .*?)` in the string. Are you sure you have "Regular Expression" turned on in the Eclipse replace box? So `<$1` means change into `
– SkillGG May 05 '21 at 19:51 -
It works in my Eclipse... [here are screenshots](https://imgur.com/a/I5jb2wn) – SkillGG May 05 '21 at 20:07
-