Skip to main content

All Questions

Filter by
Sorted by
Tagged with
3 votes
3 answers
127 views

Extract doi from a text string

I have a large list with bibliometric information including the doi like this example: ...
M.A.'s user avatar
  • 771
1 vote
1 answer
74 views

Difficulty using StringCases to obtain desired substring

I have extracted and stored some plaintext strings (derived from a pdfs) from the web that I wish to search for various values following certain text substrings that are different for different ...
Stuart Poss's user avatar
  • 1,975
3 votes
2 answers
147 views

Small trouble with variable referencing in StringReplace?

I am trying to do the following: Take a string abcdEFGpcf and replace whatever is between abcd and ...
Red Banana's user avatar
  • 5,573
1 vote
0 answers
41 views

A successful StringReplace with an error message [closed]

An example of StringReplace and RegularExpression : ...
imida k's user avatar
  • 4,345
5 votes
2 answers
290 views

StringCases with string replace and with escape characters

I want to extract url address of all css files inside HTML source. First output is as expected. But why second and third outputs are different? Notice that only "href" was removed from ...
azerbajdzan's user avatar
  • 25.1k
5 votes
2 answers
243 views

using StringReplace and StringPattern to convert exp(...) to Exp[....]

I am looking at a file generated by another CAS. I'd like to convert it to Mathematica syntax. Only issue is how to convert exp(....) to ...
Nasser's user avatar
  • 150k
5 votes
2 answers
1k views

using regex to find a specific word

I want to find the word "circle" and "circles" in the list. list = {"circle" , "picircle" , "circles" } The regex ...
Aryan's user avatar
  • 349
4 votes
3 answers
157 views

Extract the name of a point with Regular Expression

I have a list of points as strings in the form {"A1=(345.2345,3423.1)","B=(2123,97.123)","KX=(2144.546,-4455)"} and I would like to extract the names using ...
Emmet 's user avatar
  • 356
5 votes
4 answers
562 views

Regular Expression with +/-

Is it possible to extract the sign using Regular Expression ? For example {"Today+100","Yesterday-200"}. And I need {"Today",100,"Yesterday",-200}. Currently, I use Regular Expression to get the ...
Akcmok's user avatar
  • 197
5 votes
3 answers
140 views

StartOfLine and EndOfLine not working well inside Shortest

Suppose that I want to replace lines containing "b" with a new "XXX" line. This works as expected with regular expressions: ...
Gustavo Delfino's user avatar
2 votes
1 answer
182 views

How to refer to a character group without ambiguity in a regex?

Suppose I want to realize a replacement in a string: "aabbcc11dd ee" -> "aabbcc112dd ee", I can use a regex like this within ...
Αλέξανδρος Ζεγγ's user avatar
0 votes
1 answer
85 views

Evaluate until a regexp match is satisfied

How do you express the computation that, given a list of regular expressions, perform a replacement until one of them is satisfied. For instance: ...
Dean's user avatar
  • 63
9 votes
4 answers
2k views

How to convert a string having nested parentheses into an expression?

I am a Wolfram Language/Mathematica beginner and trying to convert STEP ISO10303 commands into geometrical regions. A simple command looks like ...
markilux's user avatar
  • 121
5 votes
1 answer
485 views

Use cases to select subelements by Regex

I have a nested list and would like to select a sub set of lists using a RegEx and I would prefer to use patterns (mainly for readability). ...
Dennis Guse's user avatar
8 votes
4 answers
630 views

RegEx replacement with backreference followed by a numeric literal

I have a text file which contains lines of the type: SYMATTR InstName U1 where "1" can be actually a number with 1 to 3 digits. I want to replace the above line with the following 2 lines: ...
Massimo Ortolano's user avatar
5 votes
2 answers
82 views

How to match numbers to alphabets with period and space,

ToCharacterCode["ABCD...XYZ"] - 64 I know that I can make a list of alphabets in this way. However, I need to assign " " and <...
Lee's user avatar
  • 321
6 votes
1 answer
176 views

Regex named groups -- how to refer back to them in the replacement string [duplicate]

We can use group numbers to reuse the same piece of code while inside regex string, like that: StringCases["x = y", RegularExpression["([\\w\\s]+)=(?1)"]] <...
Stitch's user avatar
  • 4,225
27 votes
1 answer
637 views

Why Except is so slow as compared to equivalent RegularExpression?

When comparing performance of the solutions suggested for this question I discovered that StringExpression involving Except is ...
Alexey Popkov's user avatar
6 votes
3 answers
688 views

Extract substring up to specific character non-inclusive

I was wondering if there is a way with StringCases to start at the beginning of a string and stop one character before a known character. ...
newtonjeep's user avatar
8 votes
4 answers
471 views

Dictionary lookups of words composed of specified characters

I am trying to find all English words composed of specified characters. For example, all words composed of one or more of the following: ...
Michael Stern's user avatar
0 votes
1 answer
125 views

How to fix this issue with storing an expression as a String and returning it with ToExpression

( Update: Note the "." in the expression, this is most likely what causes the problem. )** Starting point of my question is the following code, which works as expected: ...
nilo de roock's user avatar
6 votes
1 answer
427 views

How to iterate over a list using a Regex

I need to replace all "Nx" with "N0x" in the following, but I can't seem to figure it out. ...
Janus Syrak's user avatar
11 votes
4 answers
2k views

How to get the longest bracket pairs from a string

In C#, we can use regular expression to do some balancing groups, like we can get {<aa <bbb> <bbb> aa>, <<dfa>a>} from ...
yode's user avatar
  • 27.2k
14 votes
1 answer
157 views

What types of string patterns can't be translated into regexes and hence do not work?

In a comment to related question Oleksandr R. made an interesting remark: ... because string patterns are converted into regular expressions and matched using PCRE, they are subject to some ...
Alexey Popkov's user avatar
9 votes
1 answer
184 views

Can we use named references on the RHS in StringReplace?

In this great answer WReach demonstrated some advantages of usage of Named Patterns inside of RegularExpression and described the supported syntax: PCRE in ...
Alexey Popkov's user avatar
0 votes
2 answers
113 views

Can I use StringExpression or RegularExpression to manipulate Symbolic XML?

Please, consider an XML document containing these fields: ...
mitochondrial's user avatar
4 votes
1 answer
435 views

Extracting integers from a string

Imagine I have a block of text that contains words and numbers. I want to extract all the integers from the text. Thus, if the input is ...
Michael Stern's user avatar
14 votes
2 answers
487 views

How can one represent a string pattern with prohibited substrings?

Say I have the following string: "<hello>something WRONG</hello><hello>something else</hello>" I am trying to find code that works like the ...
user's user avatar
  • 1,897
23 votes
1 answer
527 views

Can Mathematica convert a RegularExpression into a StringExpression or vice-versa?

I know that Mathematica can perform string comparison using either StringExpression or RegularExpression. Although regular ...
Denis Cousineau's user avatar
9 votes
3 answers
2k views

How remove specified substring and everything after it to the end of a string?

If I have, say, the string, txt = "now is the time for all (good) men" then I want to remove the substring beginning with "for" and ending at the end of the ...
murray's user avatar
  • 12.1k
0 votes
1 answer
61 views

Regular expression help for arecord command output

How do I get the card number and device number alone from this string by using a regular expression to parse it? Here's the string ...
Awhite's user avatar
  • 3
4 votes
2 answers
356 views

Using parenthesized Regex backreferences in StringReplace

(I am sorry for my poor English,I'll try to use a simple sentence to convey me.) I can use StringCases to get the target to change like this ...
yode's user avatar
  • 27.2k
3 votes
2 answers
401 views

Please help translate regular expression to StringExpression

I am familiar with regular expressions in other languages (e.g., Perl, Python, ViM), but the Mathematica StringExpression is baffling me. I'd like to match strings ...
jlconlin's user avatar
  • 247
1 vote
1 answer
115 views

Are all of the numbers in my file legitimate hex numbers

I have about 10,000 hexadecimal numbers (32 digits each) in an excel file, in one column. I want to verify that all of them are indeed hexadecimal number and that no other characters are present. My ...
Mitchell Kaplan's user avatar
12 votes
2 answers
501 views

Convert recursive RegularExpression to StringExpression?

Consider the following expression for matching balanced brackets: ...
Dan Oak's user avatar
  • 638
14 votes
3 answers
564 views

Does RegularExpression support "(?R)"?

Mathematica's RegularExpression is based on Perl's PCRE library, which supports recursive regular expressions using (?R) (or, ...
2012rcampion's user avatar
  • 7,901
13 votes
6 answers
640 views

Wrong result from StringCases with Shortest

I have a list of strings like this: ...
Zihu Guo's user avatar
  • 299
3 votes
4 answers
960 views

how to extract the string using regular expressions

I have the list : a1 = {"struct name1 {","struct name2{","struct name3{","struct name4{", "struct name5{","struct lastStruct{"} I tried to extract the ...
TraceKira's user avatar
  • 383
1 vote
2 answers
293 views

text analysis: split document in separated lines

For a text analysis I want to split a large document in separated lines. Then I want to calculated for example the average number of words. A example of the document is the following: ...
Michiel van Mens's user avatar
2 votes
2 answers
78 views

Retain or delete parts of textstring in tweets

For a twitter analysis I collected many tweets. For example: ...
Michiel van Mens's user avatar
3 votes
1 answer
90 views

Convert an expression's symbols of form a$x to a[x]

I want a function that takes expressions of the following form: a$x and converts them to a[x]. In particular, consider the ...
jlperla's user avatar
  • 977
2 votes
1 answer
131 views

StringExpression: pattern reapeted one or more times matches pattern repeated zero times

I try to construct patterns using Riffle and Except StringExpression@Riffle[{"a", "b", "c"}, Except[{"=", ","}] ..] and expect it to match "a_b_c", but not "a_bc"...
user1541776's user avatar
3 votes
2 answers
219 views

Mathematica regex equvalent of \l

In normal RegEx \l will make the character to the right lowercase. However, it seems like the RegEx in Mathematica does not have this functionality. For example <...
E.O.'s user avatar
  • 1,213
10 votes
3 answers
327 views

Extracting URLs from a list of strings

If I have a list of strings: list = {"my element 1 http://link.com", "http://link2.com my element 2"} then how do I extract a list of the valid ...
Sulli's user avatar
  • 2,235
2 votes
1 answer
126 views

Make MyLogicalExpand

The function by Mathematica to expand a formulation with ANDS, ORS, NOT, XOR, and others, is LogicalExpand, let see an example: ...
Jonathan Prieto-Cubides's user avatar
5 votes
3 answers
2k views

Extract date and time from a natural language string

Is there a way to robustly extract date and time from a text? Say for example: ...The event will be held on 17/10/2013 at 3:30 PM in the room 121 and everyone is welcome... should return: ...
my account_ram's user avatar
39 votes
1 answer
2k views

Why is StringExpression faster than RegularExpression?

Edit: as noted by Albert Retey the performance difference is only seen when sub expression extraction is performed. If this test is used below the timings are similar: ...
Mr.Wizard's user avatar
  • 273k
4 votes
5 answers
743 views

A simple StringCases problem

Given this text: text1 = " A Vitamin D Deficiency (ICD-9-CM 268.9) (ICD-9-CM 268.9) 09/11/2015 01 "; Yes, the ICD code values are duplicates- possibly but ...
alancalvitti's user avatar
  • 15.2k
13 votes
1 answer
4k views

Mathematica equivalent of regex '\w{2,3}'

It beats me to write the Mathematica pattern equivalent to the regex: \w{2,3} Any ideas?
Marek Kowalczyk's user avatar
19 votes
4 answers
757 views

Balanced Shortest[] and string patterns

The pattern Shortest["A"~~__~~"B"] is oriented : It assumes the text is read from left to right and it takes the text between the first ...
andre314's user avatar
  • 19k