Extract strings between special characters - regex

Please help me in extracting the string from this text like
id1:value1,id2:value2
id1:value1a,id2:value2a
from
"[{id1:value1,id2:value2},{id1:value1a,id2:value2a}]"

{([^}]+)} will find and capture anything that is inside { }
You should include more detail in your question though and show that you have made an attempt at it yourself.

Working codes
unlist(regmatches(text, gregexpr("\\{.*?\\}", text)))
unlist(regmatches(text, gregexpr("\\{([^}]+)\\}", text)))

Related

Modx *id isnot =`` and isnot=`` not working

Hi can someone help me with the correct code for this statement because it is not working for me.
[[*id:isnot=`250` and isnot=`252`:then=`[[$qc-wrap]]`]]
A more performant syntax would be:
[[[[*id:isnot=`250`:or:isnot=`252`:then=`$qc-wrap`:else=``]]]]
Note: updated to reflect comment below. Include a hyphen in the else value, as this:
[[[[ ... :else=`-`]]]]
Also note: an empty else condition can be left off entirely.
I think using or rather than and is appropriate here.
This article is great for understanding MODX conditionals:
https://sepiariver.com/modx/modx-output-filters-if-phx-conditional-statements-tutorial/
And this one for understanding the syntax above and why it's more performant:
https://modx.com/blog/2012/09/14/tags-as-the-result-or-how-conditionals-are-like-mosquitoes/
You use wrong syntax, please fix as follows:
[[*id:isnot='250':and:isnot='252':then='[[$qc-wrap]]']]
Don't forget to replace ' with ` within this example
A simpler solution for this question is to use the :inarray output modifier to return an empty string, and use the :default output modifier to customize output for everything that doesn't match 250 or 252:
[[*id:inarray=`250,252`:then=``:default=`[[$qc-wrap]]`]]

Parsing links with regex

I have a problem I can't seem to figure out how to write a regular expression correctly. How to write a regular expression that for example if I have loaded some text the part that interests me is links that end with .m3u or m3u8. For example if i specify this input in my program
Input - player = new Player({"player-id":"1","autoplay":"false","fullscreen":"false","debug":"true","content-volume":"85","ad-volume":"30","ad-load-timeout":"15000","div-id":"videoPlayer","default-quality-index":0,"title":"\u0428\u043f\u0438\u043e\u043d, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u0435\u043d\u044f \u043a\u0438\u043d\u0443\u043b ","poster":"https://test/four/v1/video-file1/00/00/00/00/00/00/00/10/22/11/102211-480p.mp4/thumb-33000.jpg","content":{"mp4":[],"dash":"https://test/four/v1/video-file1/00/00/00/00/00/00/00/10/22/11/102211-,480,p.mp4.urlset/manifest.mpd","hls":"https://test/four/v1/video-file1/00/00/00/00/00/00/00/10/22/11/102211-,480,p.mp4.urlset/master.m3u8"},"about":"false","key":"4eeeb77181526bedc1025586d43a70fa","btn-play-pause":"true","btn-stop":"true","btn-fullscreen":"true","btn-prev-next":"false","btn-share":"true","btn-vk-share":"true","btn-twitter-share":"true","btn-facebook-share":"true","btn-google-share":"true","btn-linkedin-share":"true","quality":"true","volume":"true","timer":"true","timeline":"true","iframe-version":"true","max-hls-buffer-size":"10","time-from-cookie":"true","set-prerolls":["https://test/j/v.php?id=645"],"max-prerolls-impressions":1});
By using regex the output should be -
https://test/four/v1/video-file1/00/00/00/00/00/00/00/10/22/11/102211-,480,p.mp4.urlset/master.m3u8
I have tried writing this regex expression but it parses all links and not the ones that I need. I only need the links tht end with a specific tag
Thank you for your answer in advance
I dont see why there are so much downvotes, maybe the question looked totally different originally.
Using regex only, my solution in ASP.net would be to reverse the text first, then look up for everything between "u3m" until the next occurence of "ptth".
Play with it: http://refiddle.com/nwvu
Regex for m3u8 OR m3u:
(8u3m.+?ptth)|(u3m.+?ptth)
ASP String reversal (from https://forums.asp.net/t/1841367.aspx?Reverse+String+in+asp+net):
string input = TextBox1.Text;
char[] inputarray = input.ToCharArray();
Array.Reverse(inputarray);
string output = new string(inputarray);

Regex to eliminate a word

I have strings like
BadRequestException("hello world")
BadRequestException(BadRequestException::$errors->message)
ConflictException(ConflictException::$errors->sldkf)
ConflictException("skdljf")
How do i add a regex that gets me these two:
ConflictException("skdljf")
BadRequestException("hello world")
I tried /Exception(/ to retrieve everything.
I could not figure out a way to eliminate those strings that contain "$errors"
I tried this:
/Exception(?!errors)/
But it did not work as per my requirements.
Thanks
Figured it out.
I used
Exception(?!.*::\$errors)

How do you extract text matching a pattern in XPATH?

I have data that looks like this:
<value>v13772 #FBst0451145:w<up>1118</up>; P{GD3649}v13772#
v13773 #FBst0451146:w<up>1118</up>; P{GD3649}v13773#</value>
How can I process this string in XPATH to extract any and all #FBst####### numbers?
I know of the xpath matches() function... but that only returns true or false. No good if I want the matching string. I've searched around but cannot find a satisfactory answer to this problem, which is probably really common.
Thanks!
In addition to the good answer by Michael Kay, if you want to use only the replace() function, then use:
replace(.,'.*?(#FBst\d+).*','$1')
The result is:
#FBst0451145
#FBst0451146
And if you only want the numbers from the above result, use:
replace(replace(.,'.*?(#FBst\d+).*','$1'),
'[^0-9]+', ' ')
This produces:
0451145 0451146
I Assume you can also use XQuery. The get_matches() function from the FunctX module should work for you. Download the file which supports your version of XQuery. Then import the module whenever you need its functionality.
import module namespace functx = "http://www.functx.com" at "functx-1.0-doc-2007-01.xq";
functx:get-matches(string-join(//text()),'xyz')
Try
tokenize(value, '[^0-9]+')
which should return the sequence of tokens separated by sequences of non-digits.
With help from Dimitre, a working regex is:
replace(.,'.*?(#FBst\d+).*','$1 ','m')
Although it doesn't work unless a newline separates each target string, it will do for now.
Thanks everyone!

How to create a regex to check whether a set of words exists in a given string?

How can I write a regex to check if a set of words exist in a given string?
For example, I would like to check if a domain name contains "yahoo.com" at the end of it.
'answers.yahoo.com', would be valid.
'yahoo.com.answers', would be wrong. 'yahoo.com' must come in the end.
I got a hint from somewhere that it might be something like this.
"/^[^yahoo.com]$/"
But I am totally new to regex. So please help with this one, then I can learn further.
When asking regex questions, always specify the language or application, too!
From your history it looks like JavaScript / jQuery is most likely.
Anyway, to test that a string ends in "yahoo.com" use /.*yahoo\.com$/i
In JS code:
if (/.*yahoo\.com$/i.test (YOUR_STR) ) {
//-- It's good.
}
To test whether a set of words has at least one match, use:
/word_one|word_two|word_three/
To limit matches to just the most-common, legal sub-domains, ending with "yahoo.com", use:
/^(\w+\.)+yahoo\.com$/
(As a crude, first pass)
For other permutations, please clarify the question.