ranu
ranu

Reputation: 652

Regex(taking a specific part of one line)

I wanna take a specific part of one line, like this one below:

disk = ['C:/ParticionOne/lalala/bebebeb/disk.img], w']

I wanna take text between the quotes and before the first brackets, like that:

C:/ParticionOne/lalala/bebebeb/disk.img

How can i do that? Give me clues of how do that, thanks :D

Upvotes: 1

Views: 44

Answers (1)

arshajii
arshajii

Reputation: 129507

You can try the regex

(?<=\[')[^\]]*

where:

  • (?<=\[) is a positive lookbehind to ensure that our match is preceded by a [.
  • [^\]]* is 0 or more non-] characters.

This is what the regex looks like:

Regular expression visualization

Debuggex Demo

Upvotes: 1

Related Questions