For questions about the function RegularExpression which is used in string patterns in functions as StringCases, StringReplace, StringPosition,StringCount etc.
Questions tagged [regular-expressions]
85 questions
9
votes
2 answers
Using Regular Expression
sample2 = "this is a test to find whether pi works for other words or not as well pi pi pi potatpi pineapple pi-neapple";
so sample2 is a string, and I want to search the word/substring "pi" only, not in "pi-neapple" or "potatpi"
The code I…
Aryan
- 339
- 1
- 6
6
votes
1 answer
Split a multi-line string at the beginning of each line using RegularExpression
I want to replicate the following code using RegularExpression instead of StartOfLine:
In[1]:= StringSplit["line1\nline2\nline3",StartOfLine]//InputForm
Out[1]={"line1\n", "line2\n", "line3"}
Failed Attempt:
In[34]:=…
podge cassidy
- 483
- 2
- 6
4
votes
2 answers
How can I split strings with regex so that only numbers are selected
examples
text1 = " climb - 95/ 85 0.18 low - 4680"
text2 = "CD 3 TO F TO GD .80000E+02 .00000E+00 .00000E+00 .00000E+00 /"#
How can I get with regex in Mathematica as results:
split_text1 = {'95', '85', '0.18',…
mrz
- 11,686
- 2
- 25
- 81
4
votes
2 answers
What is a regex which matches exactly m to n characters but not more?
StringCases["abcdefg hi jkl mn opq rstuv w xy z ", RegularExpression["[a-z]{1,3}"]]
returns
{"abc", "def", "g", "hi", "jkl", "mn", "opq", "rst", "uv", "w", "xy", "z"}
so it actually chops the first match of RegularExpression["[a-z]*"] into pieces of…
Adalbert Hanßen
- 2,808
- 12
- 26
3
votes
1 answer
StringExpression inconsistency using Alternative
Preface: This will turn out to be a bad case of brain-malfunction. In any case, the precedence is surprising and I haven't checked the FullForm... the one thing we tell every new user. Oh my
This question is for reference. I believe this is a bug.…
halirutan
- 112,764
- 7
- 263
- 474
2
votes
1 answer
Regular Expression - for html objects
I did a previous research about similar questions, but I really am confuse about using html objects.
I have the following situation:
I Import a html from a url and I need to pick the numbers that are in the middle of the html objects:
" Gal
…
locometro
- 861
- 5
- 14
1
vote
2 answers
regex to find \n within quotes and not ones outside quotes
For example,
string = "ads, 32, dv, \"sdf\"
sd, 213, as, \"asd
asd\"
asd, 123 sd, \"asd\"";
There are 3 line returns \n. I want to find the second one since it is inside the quotes ("").
StringCases[string,RegularExpression["put regular…
user13892
- 9,375
- 1
- 13
- 41