I need to replace all line breaks with a ^ character using VTL. I unfortunately do not know which version of VTL I am using as it is used as the formula language within an application. Please see below with what we have so far:
#if($FIELD} !="")
#set($new = "
")
${$FIELD}.replaceAll("$new", "^" )
#end
Try plugging in the Hex code for Line Feed(0A)"
#if($FIELD.contains(//0A)) #set($FIELD2=$FIELD.replaceAll("//0A", "^")) $FIELD2
Related
How i can read 4th Value(inside "" i.e "vV0...." using Regex in below condition ?
I am updating a bit this part - Is it possible to first find Word "LaunchFileUploader" and then select the 4th Value, if there are multiple instance of LaunchFileUploader in the file just select 4th Value of first word found ? Attaching screenshot of file where this needs to be searched (In the file word is "LaunchFileUploader")
I tried this but it gives as - I need 4th value (Group 1 is giving me third value)
\bLaunchFileUploader\b(\:?.*?,){3}.*?\)
Match 1
Full match 11030-11428 LaunchFileUploader("ERM-1BLX3D04R10-0001", 1662, "2ecbb644-34fa-4919-9809-a5ff47594c2d", "8dZOPyHKBK...
Group 1. n/a "2ecbb644-34fa-4919-9809-a5ff47594c2d",
I am still looking for solution for this. Any help is aprreciated.
Depending on what's available to you to use, there's a couple of ways to do it.
Either way, this would work better if there were no new lines in the string, just plain ("value1","value2","value3","value4") etc. It'll still work, but you may need to clean up some new lines from the resulting string.
The easy way - use code for the hard part. Grab the inner string with:
(?<=\().*?(?=\))
This will get everything that's between the 2 parentheses (using positive lookarounds). In code, you could then split/explode this string on , and take the 4th item.
If you want to do it all in regex, you could use something along the lines of:
(?<=\()(?:.*?,){3}(.*?)(?=\))
This would a) match the entire contents of the parentheses and b) capture the 4th option in a capture group. To go even deeper:
(?<=\()(?:.*?,){3}\"(.*?)\"(?=\))
would capture the contents of the "" quotation marks only.
Some tools don't allow you to use lookarounds, if this is the case let me know and I'll see what other ways there are around it.
EDIT Ran this in JS console on browser. This absolutely does work.
EDIT 2 I see you've updated your question with the text you're actually searching in. This pattern will include the space and the new line character as per the copy/paste of the above text.
(?<=\(\")(?:.*?,\s?\n?){3}\"(.*?)\"(?=\))
See my second image for the test in console
This works for python and PHP:
(?<=\")(.*)(?:\"\);)\Z
Demo for Python and PHP
For Java, replace \Z with $ as follows:
(?:")(.*)(?:\"\);)$
Demo for JavaScript
NOTE: Be sure to look the captured group and not the matched group.
UPDATE:
Try this for your updated request:
"(.*)"(?:[\\);\] \/>}]*)$
Demo for updated input string
all the above regex patterns assume there is a line break after each comma
Auto-generated Java Code:
import java.util.regex.Matcher;
import java.util.regex.Pattern;
final String regex = "\"(.*)\"(?:[\\\\);\\] \\/>\\}]*)$";
final String string = "\n"
+ "}$(document).ready( function(){ PathUploader\n"
+ " (\"ERM-1BLX3D04R10-0001\", \n"
+ " 1662, \n"
+ " \"1bff5c85-7a52-4cc5-86ef-a4ccbf14c5d5\", \n"
+ "\"vV0mX3VadCSPnN8FsAO7%2fysNbP5b3SnaWWHQETFy7ORSoz9QUQUwK7jqvCEr%2f8UnHkNNVLkJedu5l%2bA%2bne%2fD%2b2F5EWVlGox95BYDhl6EEkVAVFmMlRThh1sPzPU5LLylSsR9T7TAODjtaJ2wslruS5nW1A7%2fnLB%2bljZaQhaT9vZLcFkDqLjouf9vu08K9Gmiu6neRVSaISP3cEVAmSz5kxxhV2oiEF9Y0i6Y5%2f5ASaRiW21w3054SmRF0rq3IwZzBvLx0%2fAk1m6B0gs3841b%2fw%3d%3d\"); } );//]]>";
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
final Matcher matcher = pattern.matcher(string);
while (matcher.find()) {
System.out.println("Full match: " + matcher.group(0));
for (int i = 1; i <= matcher.groupCount(); i++) {
System.out.println("Group " + i + ": " + matcher.group(i));
}
}
The question is like: Remove lines that is shorter than 5 characters before the # using Notepad++
But it differs a bit...
I have like that:
abc:123
abc:1234
abc:12345
PLEASE NOTE: abc is not on all the lines, it is just an example.
I want to remove the first line in the previous example because 123 which is after : is shorter than or not equal to 5 characters.
Any help would be appreciated.
Thanks!
Open Notepad++ find and replace choose regex mode in the search and place ^((?!.+:\d{5,}).)*$ in search and keep replace with blank and press replaceAll
^((?!.+:\d{5,}).)*$
Without knowing the language there is only so much help I can offer. I'll give you an example of how I would solve this problem in C#.
Start by creating a string for your updated file (without the short lines)
string content = "";
Read a line in from your file.
Then get a substring of the line you read in - the abc: portion and check the length.
line = line.substring(indexof(":"), length - indexof(":"))
if(line.length > 5)
{
content += line;
}
At the end, truncate your file and write content to it.
I am tying to replace this:
:b:b:b:b:b:b:b:bvoid Page_Load\(\)\n:b:b:b:b:b:b:b:b\{\n:b:b:b:b:b:b:b:b:b:b:b:b
by this
:b:b:b:b:b:b:b:bvoid Page_Load\(\)\n:b:b:b:b:b:b:b:b\{\n:b:b:b:b:b:b:b:b:b:b:b:bmyclass.dateclass.activite\(Request.ServerVariables\[\"LOGON_USER\"\].Split\('\\\\'\)\[1\], Request.Url.AbsoluteUri\);\n:b:b:b:b:b:b:b:b:b:b:b:b
. I do find the first expression using FIND, but it says that it can't find it when I use REPLACE.
Here is a sample of my code
//Affichage de la page
void Page_Load()
{
myclass.dateclass.activite(Request.ServerVariables["LOGON_USER"].Split('\\')[1], Request.Url.AbsoluteUri);
java.Text = "<script language=\"JavaScript1.2\" type=\"text/javascript\">var sess = \"" + Session["username"] + "\";var user = \"" + Request.ServerVariables["LOGON_USER"].Replace("\\", "\\\\") + "\";</script>";
Session.LCID = 3084; //Utilise des dates en format AAAA-MM-JJ
You don't need to escape round brackets or quotes when using them in the replacement string, nor does it recognise certain character codes, including :b.
Firstly, change your find string to this (the curly braces around the outside are VS's own idiosyncratic way of defining a capture group):
{void Page_Load.+\n[^\{]+\{}
Then, change your replacement string to this (note the \1 to refer to the capture group in the replacement).
\1\nmyclass.dateclass.activite(Request.ServerVariables\["LOGON_USER"\].Split('\\\\')\[1\], Request.Url.AbsoluteUri);\n
The "the following specified text was not found" error that Visual Studio gives you back is actually wrong - it's an issue with the replacement string rather than the string to find.
It's probably worth downloading something like this Regex Search and Replace Addin to save you the headache of having to deal with Visual Studio's bizarre regex syntax.
I'm using the following regular expression to find the exact occurrences in infinitives. Flag is global.
(?!to )(?<!\w) (' + word_to_search + ') (?!\w)
To give example of what I'm trying to achieve
looking for out should not bring : to outlaw
looking for out could bring : to be out of line
looking for to should not bring : to etc. just because it matches the first to
I've already done these steps, however, to cross out/off should be in the result list too. Is there any way to create an exception without compromising what I have achieved?
Thank you.
I'm still not sure I understand the question. You want to match something that looks like an infinitive verb phrase and contains the whole word word_to_search? Try this:
"\\bto\\s(?:\\w+[\\s/])*" + word_to_search + "\\b"
Remember, when you create a regex in the form of a string literal, you have to escape the backslashes. If you tried to use "\b" to specify a word boundary, it would have been interpreted as a backspace.
I know OR operator but the question was rather how to organize the structure so it can look ahead and behind. I'm going to explain what I have done so far
var strPattern:String = '(?!to )(?<!\w) (' + word_to_search + ') (?!\w)|';
strPattern+='(?!to )(?<!\w) (' + word_to_search + '\/)|';
strPattern+='(?!to )(\/' + word_to_search + ')';
var pattern:RegExp = new RegExp(strPattern, "g");
First line is the same line in my question, it searches structures like to bail out for cases where you type out. Second line is for matching structures like to cross out/off. But we need something else to match to cross out/off if the word is off. So, the third line add that extra condition.
Bumped into a somewhat weird problem... I want to turn the string:
a\left(b_{d}\right)
into
a \left( b_{d} \right)
in Scite using a Lua script.
So, I made the following Lua script for Scite:
function SpaceTexEquations()
editor:BeginUndoAction()
local sel = editor:GetSelText()
local cln3 = string.gsub(sel, "\\left(", " \\left( ")
local cln4 = string.gsub(cln3, "\\right)", " \\right) ")
editor:ReplaceSel(cln4)
editor:EndUndoAction()
end
The cln3 line works fine, however, cln4 crashes with:
/home/user/sciteLuaFunctions.lua:49: invalid pattern capture
>Lua: error occurred while processing command
I think this is because bracket characters () are reserved characters in Lua; but then, how come the cln3 line works without escaping? By the way I also tried:
-- using backslash \ as escape char:
local cln4 = string.gsub(cln3, "\\right\)", " \\right) ") -- crashes all the same
-- using percentage sign % as escape chare
local cln4 = string.gsub(cln3, "\\right%)", " \\right) ") -- does not crash, but does not match either
Could anyone tell me what would be the correct way to do this?
Thanks,
Cheers!
The correct escape character in Lua is %, so what you tried should work, I just tried
local sel = [[a\left(b_{d}\right)]]
local cln3 = string.gsub(sel, "\\left%(", " \\left( ")
local cln4 = string.gsub(cln3, "\\right%)", " \\right) ")
print (cln4)
and got
a \left( b_{d} \right)
so, this worked for me when I tried it, what did you get as a match when you tried %