Jump to content

slyfox

Member
  • Content Count

    53
  • Joined

  • Last visited

About slyfox

  • Rank
    Member

Recent Profile Visitors

667 profile views
  1. @Terminal Thank you very much. I appreciate your effort and time. I'll take a few days to figure out the logic behind the variables as I am yet to learn JS. @deanishe I would rather stick to Java Script as I plan to learn it to become better at using JS and RegEx in situations like in this thread. I don't know any programming languages as I am just a power user rather than a developer.
  2. I am trying to replace a Keyboard Maestro workflow with Alfred workflow. 1. CMD+A to select text 2. Copy to Clipboard 3. Execute Find & replace 4. Paste back the results. For step 3 my report will have this info at the top: ### Client Info - Clinic: Advanced Healthcare - Name: Mr. John Smith - Date of Birth: January 10, 1980 - Date of Loss: January 10, 2019 - Date of Assessment: January 10, 2020 I need to find and set variables: firstName = John lastName = Smith dob = January 10, 1980 dol = January 10, 2019 Then replace (content of the report): NN with firstName --> ([M][r-s]\.\s)(\w*\s)(\w*) - group 2 XX with lastName --> ([M][r-s]\.\s)(\w*\s)(\w*) - group 3 DOB with dob --> Date\s\of\s\Birth:\s(\w+\s\d{1,2}\,\s\d{4}) DOL with dol --> Date\s\of\s\Loss:\s(\w+ \d{1,2},\s\d{4})
  3. @Terminal Through some trial and error I am trying to add another RegEx find & Replace but so far nothing happens. This time I am trying to replace "DOB" with "Date of Birth: January 10, 2020" All instances of "DOB" should turn into "January 10, 2020" Also, how would you combine multiple find and replace scripts into one? #!/usr/bin/osascript -l JavaScript var dobReplacement = /(\W|^)DOB(\W|$)/gm; function getDateofBirth(s) { let dob = /(?:Date\sof\sBirth:\s)?:(\w+\s\d{1,2}\,\s\d{4})/; return s.match(dob)[1] } function replaceDOB(s) { s = s.replace(dobReplacement, "$1"+getDateofBirth+"$2"); return s; } function run(argv) { return cleanup(argv[0]); }
  4. @Terminal Almost there. @deanishe Sorry, I'll be more specific. input: Mr. John Smith Mr. XX goes to town. Output: Mr. John Smith Mr. Smithgoes to town. Javascript used #!/usr/bin/osascript -l JavaScript var replacements = [ ]; var nameReplacement = /(\W|^)XX(\W|$)/gm; function getName(s) { let lastname = /(?:[M][r-s]\.\s)(?:\w+)(\s\w*)/; return s.match(lastname)[1] } function cleanup(s) { replacements.forEach(function(l) { s = s.replace(l[0], l[1]); }); s = s.replace(nameReplacement, getName(s)); return s; } function run(argv) { return cleanup(argv[0]); } Can I also ask (trying to understand) 1. Why do we need line 2-5? Can't we just start with line var nameReplacement = /(\W|^)XX(\W|$)/gm; 2. return s.match(lastname)[1] --> Why is there a number 1 rather then number 3? I thought that the last name will be group $3 in RegEx
  5. I am trying to figure out how to convert a simple Keyboard Maestro (KM) text manipulation workflow into Drafts action. Please note that I don't know Java Script but perhaps with some examples, I can figure out the basics principles of RegEx Find & Replace in Javascript. A plain text document contains an instance of "Mr. John Smith" (name varies) The rest of the document refers to the client as Mr. XX. My KM workflow copies text to clipboard and then runs the RegEx with variables. `/([M][r-s]\.\s)(\w*\s)(\w*)/g;` Where: Group 1 = Mr. Group 2 = John Group 3 = Smith Group 2 is set to variable FirstName Group 3 is set to variable LastName I then tell KM to replace all instances of XX with LastName variable. Based on the solution in this forum post for Find & Replace as well as as this forum post - https://forums.getdrafts.com/t/regex-find-and-replace-with-variables/6294/11?u=slyfox I tried to figure this out myself but it does not seem to be working. Can you please advise how to make this work? #!/usr/bin/osascript -l JavaScript var replacements = [ // (\W|^) matches non-word character or start // (\W|$) matches non-word character or end // $1 and $2 are the first and second match groups, // where a match group is whatever matches the contents // of a pair of parentheses. [/(\W|^)XX(\W|$)/gm, '$1/([M][r-s]\.\s)(\w*\s)(\w*)/)[3]$2'], ]; function feminise(s) { replacements.forEach(function(l) { s = s.replace(l[0], l[1]); }); return s; } function run(argv) { return cleanReport(argv[0]); }
  6. This I know. I was under the impression that this formula can be included into "Arg and Var" utility somehow to do the calculation inside the workflow. Or this is only possible with a script? Not sure what I am doing here with a script though,.
  7. Where specifically in the Argument and Variables Utility should I enter the math formula? "=round({query}/10)"
  8. Can you please show a screenshot where exactly to add the math formula to "Arg and Vars" as the link is dead?
  9. @deanishe Thank you for the script. It works. Any idea why when the new content is pasted, there is a new line at the bottom whereas the original content does not have a new line?
  10. There is a space after “He “ and “She “
  11. They are the same as the notes. Replace He with She Replace Mr with Ms I am using basic string replace.
  12. "If you post some sample input and the expected output, sure." @deanishe Are the examples (i.e., Mr. to Ms.) in the screenshots not clear?
×
×
  • Create New...