How can I remove from string the four first characters with iMacros.
I know it something with EVAL function but don't know how to write it.
TY
I know nothing of iMacros, but a quick look at the docs suggests
SET !SHORTENEDSTRING = EVAL("\"{{!EXTRACT}}\".substr(4)")
The \" escapes the double-quote characters inside the string. {{!EXTRACT}} is for what was extracted by a previous iMacros statement. The .substr(4) is a JavaScript function: MDN substr documentation, and remember that it uses a zero-based index.
Related
I would like to append _OLD to the end of each strings that starts with SR_ but before the symbol ' or without it
For example my text is the following:
SR_Apple
When the 'SR_APPLE' rotten, we must discard it.
I would like the find and replace to do:
SR_Apple_OLD
When the 'SR_APPLE_OLD' rotten, we must discard it.
I have tried (SR_*)+$.*(?='\s) based on what i Learned but no luck so far. Please help. Thx in Adv
For simple cases you should be able to use
Find: (\bSR_[\w]+)
Replace: $1_OLD
(\bSR_.+?)('|$) and $1_OLD$2 could also work if the text after SR_ is more complex
The lookbehind you're using is only matching the string if it ends with a ' so it won't find the text not in quotes.
regex101 is a useful tool for debugging expressions
I'm trying to make a regex expression to detect a URL with a dynamic ending from a message. So for example it would be something like this.
"http://loclhost/something/randomstring example text example text example text"
So the "http://localhost/something/" will always be the same but the random string part wont and I want to grab "http://loclhost/something/randomstring" only...
I've tried doing this expression
"/http://localhost/something/(.*) "
The thing is, it selects the whole text. I've tried looking up online but can't find anything. Would love some help :)
The .* will keep 'eating up' characters. You probably want something like
/http:\/\/localhost\/something\/([^\s]*)/
to make it 'stop' at a white-space character. Or
/http:\/\/localhost\/something\/([a-z0-9]*)/
if you are sure that randomstring only contains alpha-numerical characters.
Example: https://regex101.com/r/U12o53/1
You need to modify the (.*) part of the url so it only contains valid url characters, e.g.
/http:\/\/localhost\/something\/([\d\w\-_]*)/
You can modify it as you need based on the characters that can be in randomstring.
My source text could be any number of characters between "[" an "]" at the beginning of the line. I will have ONLY one line.
For example:
[1] and some other text here
[10] more text, but maybe some brackets [KEY]
[1000000] a lot more text
I want to match/return the text between the "[" and "]".
EDIT AFTER ANSWER PROVIDED
The first answer, provided by #nickb worked for me with this AppleScript:
Note that I had to convert the RegEx to a quoted string to use in AS. This uses the Satimage AppleScript Additions find text command, which provides the RegEx engine for AppleScript.
set strRegEx to "^\\[(.*?)\\]" -- Original: "^\[(.*?)\]"
set strTextToSearch to "[10] My Note title with [KEY] "
set strCaptureGroup to find text strRegEx in strTextToSearch using {"\\1"} with regexp and string result
log strCaptureGroup
-->10
The most simple regex you could use would be this:
^\[(.*?)\]
You can see it matching your input here.
Alternatively a pure AppleScript solution
set theText to "[1] and some other text here
[10] more text, but maybe some brackets [KEY]
[1000000] a lot more text"
set resultList to {}
set {TID, text item delimiters} to {text item delimiters, "]"}
repeat with aLine in (get paragraphs of theText)
if aLine starts with "[" then set end of resultList to text 2 thru -1 of text item 1 of aLine
end repeat
set text item delimiters to TID
resultList -- {"1", "10", "1000000"}
I think this will fit your criteria:
^\[([^]]*)\].*
With the stuff in brackets in the first matching group returned.
You can try runing the following reg. exp. on each line:
[^\[]\w+[^\]]
I tested it at regex101 and it matches the contents inside the [], excluding the brackets.
/^\[(.*?)\]/
is really the most simple regex for this case, but it matches surrounding brackets too.
The exact value (without brackets) is stored in 1st capture group.
If you don't want to match brackets, you will need this:
/(?<=^\[).*?(?=\])/
… unless you're using JavaScript – unfortunately, JS doesn't support lookbehinds.
In this case you'll need this regex:
/^[^\[\]]+/
(assuming that every input will start with […] component, and will not be empty)
The regex to use depends on how you are going to use it for the input it will parse. Some of the answers here have a trailing .* and some do not. Both are correct, it just depends on what exactly you are trying to match, and crucially how you ask it about a match. For example, in Java, with the regex ^\[(.*?)\], if you feed it the whole string "[1000000] a lot more text" and call matches(), it will return false because the regex pattern does not account for any of the trailing text outside the brackets. However, if you call find() after feeding in the same string, it will match because find() works on each substring as it parses and will return true on the first match it hits, while matches() will only return true if the entire input matches the regex. find() will also find subsequent substring matches to the regex in the string each time find() is called until the parser reaches the end of the input.
Personally, I like to use regex that account for the entire input and use capture groups to isolate the actual text I want to grab from the input. But your mileage may vary.
I'm trying to select a substring using regex and I'm going round in circles. I need to select everything before the first "_".
exampale URL - GI_2013_JUNE_10_VOL3_LASTCHANCE
So the result Im looking for from the URL above would be "GI". The text before the first "_" can vary in length.
Any help would be much apprecited
The regex would be:
^[^_]+
and grab the whole regex match. But as a comment says, using a substring function is more efficient!
^[^_]*
...is the expression you're looking for.
It basically says: Select everything that is not an underscore, starting at the beginning of the string.
http://regexr.com?356in
Given a file path such as: \\server\folder_A\folder_B\etc\more.mov
I need a regex that'll give me the last backslash so I can extract the actual file name.
My attempt of "$\\" is not returning anything.
I'm using coldfusion.
Suggestions...?
What about
<cfset fileName = GetFileFromPath("\\server\folder_A\folder_B\etc\more.mov") />
Do you just want everything after the last backslash (the filename)?
([^\\]+)$
The filename will be contained in the capture.
To match starting at the last backslash you'd do...
\\[^\\]+$
I'm not familiar with coldfusion, but I'm assuming that if it does regular expressions, it does captures as well. If you do really need the position and can get that from the match, the second expression might be what you want.
(Edited for clarity and to answer comment)
Do you absolutely have to use regex? Why not split the string and grab the last element?
<cfset fileName = ListLast(filePath, "\\")>