How to add paragraph between mergefields in word mailmerge - mailmerge

I want to be able to add an automatic paragraph between mergefields in mailmerge. The words of the merge fields are written together with no space between them. how do I format it in this way?

If you have two consecutive mergefields looking like <<field1>> <<field2>> couldn't you just do something like:-
document.merge(field1='your field1 text here\n', field2='your field2 text here')
The \n will insert the newline at the end of field1.

Related

Regular expression to remove a portion of text from each entry in commas separated list

I have a string of comma separated values, that I want to trim down for display purpose.
The string is a comma separated list of values of varying lengths and number of list entries.
Each entry in the list is formatted as a five character pattern in the format "##-NX" followed by some text.
e.g., "01-NX sometext, 02-NX morertext, 09-NX othertext, 12-NX etc..."
Is there an regular expression function I can use to remove the text after the 5 character prefix portion of each entry in the list, returning "01-NX, 02-NX, 09-NX, 12-NX,..."?
I am a novice with regular expressions and I haven't been able figure out how to code the pattern.
I think what you need is
regexp_replace(regexp_replace(mystring, '(\d{2}-NX)(.*?)(,)', '\1\3'), '(\d{2}.*NX).*', '\1')
The inner REGEXP_REPLACE looks for a pattern like nn-NX (two numeric characters followed by "-NX") and any number of characters up to the next comma, then replaces it with the first and third term, dropping the "any number of characters" part.
The outer REGEXP_REPLACE looks for a pattern like two numeric characters followed by any number of characters up to the last NX, and keeps that part of the string.
Here is the Oracle code I used for testing:
with a as (
select '01-NX sometext, 02-NX morertext, 09-NX othertext, 12-NX etc.' as myString
from dual
)
select mystring
, regexp_replace(regexp_replace(mystring, '(\d{2}-NX)(.*?)(,)', '\1\3'), '(\d{2}.*NX).*', '\1') as output
from a
This alternative calls REGEXP_REPLACE() once.
Match 2 digits, a dash and 'NX' followed by any number of zero or more characters (non-greedy) where followed by a comma or the end of the string. Replace with the first group and the 3rd group which will be either the comma or the end of the string.
EDIT: Took dougp's advice and eliminated the RTRIM by adding the 3rd capture group. Thanks for that!
WITH tbl(str) AS (
SELECT '01-NX sometext, 02-NX morertext, 09-NX othertext, 12-NX etc.' FROM dual
)
SELECT
REGEXP_REPLACE(str, '(\d{2}-NX)(.*?)(,|$)', '\1\3') str
from tbl;

Power Query - How to extract after delimiter

I have info in a column, that needs to be split into two columns. It can be shown like:
1,000,1111,000 - what we should see is 1,000,111 - 1,000 - or
1,1111,100 - what we should see is 1,111 - 1,100
etc.
I need to separate these columns. I assume the conditions should be "If there are four digits after a comma, separate at this point, into two columns.
It's not immediately obvious how I should fix this. Any thoughts?
EDIT: essentially, the criteria is: If the 4th character after any comma is not another comma, move the 4th character onward onto another column.
This query splits the text string into a list, using its commas as delimiters; then looks at each list entry to find the one that is greater than 3 digits; then inserts a semicolon after the 3rd digit of that entry that is longer than 3 digits; then recombines the list into a text string, with commas; then splits that recombined string into two columns, using the semicolon as the delimiter.
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
Custom1 = Table.TransformColumns(Source, {"Column1", each Text.Combine(List.Transform(Text.Split(_,","), each if Text.Length(_) > 3 then Text.Insert(_,3,";") else _),",")}),
#"Split Column by Delimiter" = Table.SplitColumn(Custom1, "Column1", Splitter.SplitTextByDelimiter(";", QuoteStyle.Csv), {"Column1.1", "Column1.2"})
in
#"Split Column by Delimiter"
The table I used to develop/test this is simply this table, which I named Table1:
The query result looks like this:

AWK filter data by characters

A data set like below:
07021201180934221NJL B2018 12X 15253 030C 000000.299
07021201180934231NSL B2018 12X 15253 030C 00000.014
07021201180941061NNL B2018 030C 000000.288
Questions are:
The characters in the first string "120118" means date "ddmmyy", how could I filter rows according to date characters using awk?
The characters in first string "NJL" or "NSL" or "NNL" means data type, what awk command to filter lines according to those three characters?
The third column could be some description like "12X 15253" or empty, how could I filter data out if the column is empty?
Thanks in advance!
this script has all the conditions
$ awk 'substr($1,5,6)==120118 && substr($1,length($1)-2)=="NNL" && $3$4==""' file

Separate word Regex Ruby

I have a bunch of input files in a loop and I am extracting tag from them. However, I want to separate some of the words. The incoming strings are in the form cs### where ### => is any number from 0-9. I want the result to be cs ###. The closest answer I found was this, Regex to separate Numeric from Alpha . But I cannot get this to work, as the string is being predefined (Static) and mine changes.
Found answer:
Nevermind, I found the answer the following sperates alpha-numeric characters and removes any unwanted non-alphanumeric characters so anything like ab5#6$% =>ab 56
gsub(/(?<=[0-9])(?=[a-z])|(?<=[a-z])(?=[0-9])/i, ' ').gsub(/[^0-9a-z ]/i, ' ')
If your string is something like
str = "cs3232
cs23
cs423"
Then you can do something like
str.scan(/((cs)(\d{1,10}))/m).collect{|e| e.shift; e }
# [["cs", "3232"], ["cs", "23"], ["cs", "423"]]

Parsing String in Ruby then Storing to Database

I'd like to parse string for two different tags then store each in the database. Let's call these tag1 and tag2. I have a delimeter of sorts, "?#" that is the split between tag1 and tag2.
Suppose
t = "random text blah firsttag?#secondtag more blah"
Goal: tag1 should be "firsttag" and tag2 should be "secondtag" without the preceding or trailing random text. Each should get stored as objects in the database.
I tried something like:
t.split
but it returns
["random text blah firsttag", "secondtag more blah"]
and includes the random text. How can I get the split to stop when it reaches the first space in either direction?
I'd like this to also work if there are multiple tag pairs in the string, for example, if:
m = "random firsttag#?secondtag blah blah 1sttag#?2ndtag blah blah blah"
I'm pretty new to both ruby and rails, so I really appreciate your help on this one!
You can use a regular expression combined with split:
tags = t.match(/\S+\?#\S+/)[0].split('?#')
Explanation
First let's capture the interesting part of the text, which is tag?#tag2. We'll use a regex for that:
/\S+\?#\S+/
Explanation:
\S+ captures non-whitespace characters preceding the delimiter (tag)
\?# captures the delimiter token
\S+ captures all trailing non-whitespace chars (tag2)
The match of that regex (which we access with [0] is:
firsttag?#secondtag
Then from that we just split using the delimiter and we get the array with the tags.
Cheers!
PS: I've retagged the post since it has nothing to do with ruby-on-rails. It's just plain ruby

Resources