I have recently been started to play around with Redis (and am extremely pleased with all the functions it has to offer).
In particular, I was looking for a way to find all elements within a set for which a regex matches.
For example:
>>smember WORDS
1) "person"
2) "saint church"
3) "saint house"
If I wanted to return only the elements where "saint" is present, how would I do so?
I have tried to use sscan as follows:
sscan WORDS match *saint*
for which I get an error.
My understanding was that sscan can return "array of elements is a list of Set members"
Please help! Thanks!
Assuming that you have no more than 1000 elements matching you can use
sscan WORDS 0 match *saint* count 1000
If you want know the exact numbers of the elements in the set you can use SMEMBERS command.
If you want know the exact numbers of the elements in the set that MATCH with your regex, in a single command no a specific command.
Just add a ZERO as the cursor parameter for the SCAN:
sscan WORDS 0 match *saint*
Related
I want to be able to match and parse some parameters read from a file such as :
"type:int,register_id:15,value:123456"
"type:int,register_id:16,value:-456789"
"type:double,register_id:17,value:123.456"
"type:double,register_id:18,value:-456.789"
"type:bool,register_id:19,value:true"
"type:bool,register_id:20,value:false"
"type:string,register_id:17,value:Test Set Data Register"
I've come up with the following Regex expression :
(^(type:)\b(bool|int|double|string)\b,(\bregister_id:\b)([1-9][0-9]),(\bvalue:\b)(.)$)
but I have issues where there are negative floats or ints, I can't get the hyphen sorted properly ...
Can someone point me in the right direction ?
https://regex101.com/r/WhXmBE/3
Thanks !
Tried [\s\S] but it reads everything, tried -? as well
Given your example, this seems to work:
(^(type:)(bool|int|double|string),(register_id:)([1-9][0-9]*),(value:)(.*)$)
At least from the example, I didn't see why the \b are necessary. Apologies if I missed something.
Looking at what you try to achieve, I would actually consider moving away from regexes, as regexes by themselves add complexity. You will likely have an easier life if you approach it like this:
Split the line by "," to get the key value pairs
Split each key value pair by the first ":" to split key and value
Validate that all keys are present and that every value matches the format for the key (e.g. if the type is bool then the value should parse to a bool)
You can easily adjust every step to e.g. trim whitespaces.
Edit: Fixed typo
So I'm using Regexextract in GoogleSheet to find the value for a big amount of data. I have 2 problems I don't know to extract or what I did wrong. Feel free to point out my mistakes and help me with a solution.
Require: I need to extract the part number which format is ABCD#### or ABCD-#### which is is Upper character and numbers follow after, with or w/o "-" , for example KTA1763 or SPD-4124
# I use this formula: =Regexextract(A1,"([A-Z]+-?[0-9]*)") .FYI, the values I'm extracting, it could appear either at the beginning, middle or last.
1.First problem, I have the value as below:
REACH TECH 223/224 list document for KTD2026BEWE-TR
=> Extract result : REACH
[What I need: KTD2026]
2.I have the value as:
information for Part number KTA1550EDS-TR
=> Extract result: P
[What I need: KTA1550]
Please let me know which part in the formula should I fix to have the final expected result. Or how should I alter my formula for that matter, big thanks
go for:
=INDEX(IFNA(REGEXEXTRACT(A1:A, "[A-Z]+\d+")))
Try this in one cell.
=ArrayFormula(IF(A2:A="",,REGEXEXTRACT(REGEXEXTRACT(A2:A, ".+"®EXEXTRACT(A2:A, "[0-9]+")), ".+\s(.+)")))
I have multiple cells that I am attempting to extract a number from, and need help finding a regex alternative.
The cells range in the following formats:
asdfs. Seat#29 asfddsa
asdfsa. Seat#5d
asdfasN/A . Seat#22 as789fsd
Seat#111 words33
The closest that I came to a solution is:
=IFERROR(TRIM(MID([#DisplayName],FIND("#",[#DisplayName])+1,3)),"")
As you can see this will extract most of the numbers but for some it leaves a character at the end.
The only commonality is the # preceding the seat number. I am trying to extract only the seat number, no other numbers.
I cannot use VBA, this must be done using formulas. I have figured this out once before but stupidly pasted over the formulas with a values only paste.
This can be done utilizing a flash fill, but I was hoping for a more stable formula.
If you want just the numbers then use:
=--MID(A1,FIND("#",A1)+1,AGGREGATE(15,6,ROW(1:5)/(ISERROR(--MID(REPLACE(A1,1,FIND("#",A1),""),ROW(1:5),1))),1)-1)
If you want the letter also then:
=MID(A1,FIND("#",A1)+1,FIND(" ",REPLACE(A1,1,FIND("#",A1),""))-1)
If you do not need the letter following the seat number, you can use
.*#(\d+)
Edit for clarity: Excel does not have regex functions built in. You will either have to use a UDF (I can help with that if you'd like) or use a non-regex solution.
Here is a solution without VBA to extract all numbers inside the strings.
https://drive.google.com/open?id=1Fk6VFznD3i8s6scADy_vXCEj-1zQpBPW
Sheet #3
I have been trying to apply the technique offered by ib in another answer on stackoverflow, cannot get it to work in m case.
I am trying to extract a list of numbers from text with reference links in this format
[1]:www.example.com
[2]:www.example.2.com
After extracting the numbers I wish to get the maximum value from the list so that I can find the next appropriate number to use.
It was suggested in a excellent answer here:
How to extract regex matches using Vim
to another person that the following format might work:
:let nextreflink=[] | %s/\d\zs/\=add(nextreflink,submatch(1))[1:0]/g
However, when calling "echo new", in my case, the list is empty.
Any ideas would be very welcome!
The following explicitly matches "[N]" at the beginning of the line so it's a little more strict. This is similar to the answer above but it does not remove the numbers from the references (I'm not really sure what's going on with that).
let refs=[] | %s/^\[\zs\d\+\ze\]/\=add(refs, submatch(0))[-1]/g
This leaves the reference list in tact. Then you can get the next available reference with:
let next = max(refs) + 1
This does not take into account skipped numbers. If the references were [1, 2, 5] then next will be 6.
You need to capture the number matched by \d by enclosing it in \(...\); the submatch(1) refers to the first capture. Also, you probably want to match multiple numbers \d\+ to support more than nine references.
:let nextreflink=[] | %s/\(\d\+\)\zs/\=add(nextreflink,submatch(1))[1:0]/g
I have a list of numbers that I want to find at least 3 of...
here is an example
I have a large list of numbers in a sql database in the format of (for example)
01-02-03-04-05-06
06-08-19-24-25-36
etc etc
basically 6 random numbers between 0 and 99.
Now I want to find the strings where at least 3 of a set of given numbers occurs.
For example:
given: 01-02-03-10-11-12
return the strings that have at least 3 of those numbers in them.
eg
01-05-06-09-10-12 would match
03-08-10-12-18-22 would match
03-09-12-18-22-38 would not
I am thinking that there might be some algorithm or even regular expression that could match this... but my lack of computer science textbook experience is tripping me up I think.
No - this is not a homework question! This is for an actual application!
I am developing in ruby, but any language answer would be appreciated
You can use a string replacement to replace - with | to turn 01-02-03-10-11-12 into 01|02|03|10|11|12. Then wrap it like this:
((01|02|03|10|11|12).*){3}
This will find any of the digit pairs, then ignore any number of characters... 3 times. If it matches, then success.