0

I'm trying to find all white spaces in string defined by begining as "jpeg" and ending with 600), in order to replace them with "_" but how do I catch all the \s in the string?

I'm working on sublime text editor / notepad++

I tried:

^jpeg.*(\s).*600\)$

Thanks for the help Example of text that is being edited:

# CHART: Share of persons living at risk of poverty or social exclusion ====
df <- S3R0004_M3080242 %>% 
        mutate(LAIKOTARPIS=parse_date_time(LAIKOTARPIS, "y")) 
jpeg("./figures/Share of persons living at risk of poverty or social exclusion.jpeg", width = 9, height = 6, units = 'in', res = 600)
ggplot(data = df, aes(x=LAIKOTARPIS, y=obsValue)+
Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
Justas Mundeikis
  • 935
  • 1
  • 10
  • 19
  • 2
    please keep the expected output too – rahul Sep 30 '18 at 10:39
  • 2
    Can you show a reproducible example? Please include all packages you use. – markus Sep 30 '18 at 10:40
  • 1
    Also, it seems your code is not complete in the `ggplot` line. – s__ Sep 30 '18 at 10:41
  • Could you please clarify: Are you trying to do this in the find/replace dialog of sublimetext3 (code editor) or write R code to replace text you've read into a variable? – krads Sep 30 '18 at 10:44
  • Read https://stackoverflow.com/questions/4736/learning-regular-expressions HTH – jogo Sep 30 '18 at 10:53
  • I'm trying to edit the R code in sublime text editor with search and replace. The names of the jpeg file should not contain any white-space, else I get problems with including them in latex. Therefore the fullness of the R code is not necessary, as i only intend to replace the whitespaces in lines such as {jpeg("./figures/Share of persons living at risk of poverty or social exclusion.jpeg", width = 9, height = 6, units = 'in', res = 600)} – Justas Mundeikis Sep 30 '18 at 11:02
  • What is the expected result? `jpeg("./figures/Share_of_persons_living_at_risk_of_poverty_or_social_exclusion.jpeg", width = 9, height = 6, units = 'in', res = 600)` – Wiktor Stribiżew Sep 30 '18 at 11:40
  • 1
    Try `(?:\G(?!\A)|jpeg\("(?=[^"]*"[^)]*600\)))[^\s"]*\K\s+` and replace with `_`. See [demo](https://regex101.com/r/zlQJHp/1). – Wiktor Stribiżew Sep 30 '18 at 11:43
  • Any feedback??? – Wiktor Stribiżew Oct 02 '18 at 16:52
  • Thanks @WiktorStribiżew it worked and saved hell lot of time! – Justas Mundeikis Oct 05 '18 at 12:51

1 Answers1

1

You may use

Find what:      (?:\G(?!\A)|jpeg\("(?=[^"]*"[^)]*600\)))[^\s"]*\K\s+
Replace With: _

See the regex demo.

Details

  • (?:\G(?!\A)|jpeg\("(?=[^"]*"[^)]*600\))) - matches either
    • \G(?!\A) - the end of the preceding match
    • | - or
    • jpeg\("(?=[^"]*"[^)]*600\)) - jpeg(" followed with any 0+ chars other than " (with [^"]*), then " and then any 0+ chars other than ) and then 600)
  • [^\s"]* - matches and consumes 0+ chars other than whitespace and "
  • \K - match reset operator, the text matched before is cleared from the match buffer
  • \s+ - 1+ whitespaces (they will be replaced).
Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563