Skip to main content

All Questions

Tagged with
0 votes
2 answers
50 views

Replace a certain part of the string which matches a pattern in python 2.7 and save in the same file

I am trying to achieve something of this sort My input file has this kind of entries art.range.field = 100 art.net.cap = 200 art.net.ht = 1000 art.net.dep = 8000 I am trying to match the pattern like ...
Saswata Kar's user avatar
-2 votes
2 answers
220 views

Replace only the first character that appears in every line using regex [duplicate]

I have a string like this one: AAA;BBB;CCC DDD;EEE;FFF AAA;PPP;GGG And I would like to transform it to something like this: AAA.BBB;CCC DDD.EEE;FFF AAA.PPP;GGG With this regex, I can take the first ...
aldegalan's user avatar
  • 502
7 votes
1 answer
4k views

How to remove duplicate phrases in Python?

Suppose I have a string such as 'I hate *some* kinds of duplicate. This string has a duplicate phrase, duplicate phrase.' I want to remove the second occurrence of duplicate phrase without removing ...
duckmayr's user avatar
  • 17k
0 votes
1 answer
235 views

Ansible replace module regexp starting with '$'

I'm trying to use replace module from Ansible, and I don't know how to match some string using regexp. I'm trying to match a string starting with the character $ but ansible keeps saying that he ...
Ricardo Mendes's user avatar
2 votes
1 answer
3k views

pandas convert numbers to words in every rows and one specific column

UPDATE df = pd.DataFrame(np.random.randint(0,100,size=(100, 4)), columns=list('ABCD')) df.iloc[:,3].replace(r'(?<!\S)\d+(?!\S)', lambda x: p.number_to_words(x.group()), regex=True, inplace=True) ...
Shew's user avatar
  • 1,596
1 vote
1 answer
54 views

Need to find 2 strings using regex with multiple lines of text between them and insert replacement text

I need perform a regular expression find and replace, many times in a large html file. The first string to find is the following: (?-i)(<p class=.+\r\n.+)([\d]{2}/[\d]{2}/[\d]{4})(((.+\r\n)+?)(.+&...
Marc B. Hankin's user avatar
2 votes
1 answer
471 views

Strict regex in Pandas replace

I need to write a strict regular expression to replace certain values in my pandas dataframe. This is an issue that was raised after solving the question that I posted here. The issue is that the ....
owwoow14's user avatar
  • 1,754
17 votes
2 answers
19k views

Check for words from list and remove those words in pandas dataframe column

I have a list as follows, remove_words = ['abc', 'deff', 'pls'] The following is the data frame which I am having with column name 'string' data['string'] 0 abc stack overflow 1 abc123 2 ...
haimen's user avatar
  • 2,015
1 vote
1 answer
294 views

separating letters and non alphabetic characters from a non-English text in Python

I am scraping a Portuguese website in Python 2.7, and I want to separate Latin words and numbers which are between parentheses. Each text looks like: text = 'Obras de revisão e recuperação (45453000-...
mk_sch's user avatar
  • 1,070
2 votes
2 answers
2k views

Replace all hex encodings in a python string with equivalent ascii values

I have a string that contains hex values inside brackets. I need to find all those strings and replace them with the decoded values. Example input: MainDir[0x2f]SubDir[0x2f]Hello[0x2d]world[0x2e]txt ...
user3885927's user avatar
  • 3,523
1 vote
3 answers
1k views

Using re.sub() to replace some part of a string

background I'm trying to use re to replace some value in a string. Essentially, replace the first detected int (in a specific pattern) with 1. Examples: {1} -> {1} {2} -> {1} {3,} ...
idanshmu's user avatar
  • 5,281
-1 votes
4 answers
2k views

Python: Replace all substring occurrences with regular expressions

I would like to replace all substring occurrences with regular expressions. The original sentences would be like: mystring = "Carl's house is big. He is asking 1M for that(the house)." Now let's ...
user2288043's user avatar
0 votes
1 answer
65 views

How to replace all matched (regex) back to the list to remove them without TypeError: expected a string or other character buffer object

My file has differents urls: www.example.com www.example.com/validagain www.example.com/search?q=jsdajasj;kdas --> trying to get rid off www.example.com/anothervalid I was able to isolate the /...
peaceandiago's user avatar
3 votes
1 answer
1k views

Regex - match a pattern (from capture) before a capture group

I have to match text with this scheme: capture [\w-/]* which are not ['] (\1) capture [']+ which follow (\2) and replace \2\1\2 with \1 Example: my input text is: l''''text''' the right output is: l'...
Nicholas Roveda's user avatar
0 votes
1 answer
54 views

regular expression replace (if pattern found replace symbol for symbol)

I have several lines of text (RNA sequence), I want to make a matrix regarding conservation of characters, because they are aligned according similarity. But I have several gaps (-) which actually ...
Nelly's user avatar
  • 39

15 30 50 per page