Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Is there a way to make a replacement pattern for the "Find replace REGEX" plugin that includes a newline character? I've tried \n and \r and %n without success.
What ended up doing was creating a new plugin based on the existing one but changing this part (lines 25–26 of find_replace_regex.inc):
$form['replace'] = array(
'#type' => 'textarea', // modified from 'textfield'
Now I can just hit enter/return in the text box and my text is replaced with a newline.
Is this crazy or a good enough way to do it?
Comment | File | Size | Author |
---|---|---|---|
#4 | feeds_tamper-regex-newline-1356384-4.patch | 727 bytes | twistor |
Comments
Comment #1
twistor CreditAttribution: twistor commentedIt looks like you resolved this, but \n should work fine. Are you sure the text was using UNIX line endings?
Comment #2
aeggenberger CreditAttribution: aeggenberger commentedI have the same problem. Using \n literally adds \n where the newline should be. I've tried with \r\n and got the same result.
Comment #3
aeggenberger CreditAttribution: aeggenberger commentedComment #4
twistor CreditAttribution: twistor commentedPerhaps this would work?
Comment #7
twistor CreditAttribution: twistor commentedI've added a test case that confirms that this works. You might want to try \s instead, in case there is other white space.
Comment #9
BWPanda CreditAttribution: BWPanda commentedThis didn't work for me until I patched the module with the patch from #4 (i.e. it hasn't been committed yet...)
Comment #10
komlenic CreditAttribution: komlenic as a volunteer commentedI've tested this both with and without the patch and I have yet to see a \r or \n or \r\n not just get inserted into the string literally.
The accepted answer to this stackexchange question *did* work: https://drupal.stackexchange.com/questions/62713/how-do-i-replace-a-comm...