-6

How can I match a pattern and extract in between particular expressions of a string ? here in between ${ and }

string = '''${data1}, ${data2}, ${data3}... ''' 

so my question is how can I extract `data1,data2 .... in the entire string?

3
  • 3
    The posted question does not appear to include any attempt at all to solve the problem. StackOverflow expects you to try to solve your own problem first, as your attempts help us to better understand what you want. Please edit the question to show what you've tried, so as to illustrate a specific roadblock you're running into a minimal reproducible example. For more information, please see How to Ask and take the tour. Commented Dec 31, 2018 at 5:37
  • Question is not clear and not well formatted. Commented Dec 31, 2018 at 5:42
  • you can use regex for this one. @Techielife Commented Dec 31, 2018 at 5:42

1 Answer 1

0

Try this one with the help of regex.

In [105]: import re In [106]: m = re.findall('\${(.+?)}', string) In [107]: m Out[107]: ['data1', 'data2', 'data3'] 
Sign up to request clarification or add additional context in comments.

7 Comments

Thanks @Rohit : One more doubt ,if i want to do any manipulation on that data and replace it in the string again , how can i achieve it?
Hey @Techielife you can you re.sub for replacing.
Refer this one for this : Read This
i tried re.sub('\${=(.+?)}>', '\<c:out value = "${ (.+?) " />', string ) , but the data1,data2 and data3 variables are being ignored
What do you want to achieve?
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.