Results 1 to 4 of 4

Thread: Simple Scripting Question

  1. Default Simple Scripting Question

    How do I pass data to a variable?

    For example, if I want to create a variable Devotion_Status and use fput "resource" how would I do that?

  2. #2

    Default

    You would need to use a regex for that.

    Code:
    fput "resource"
    while line = get
    	if line =~ /Devotion: (.*)\/50,000 \(Weekly\)     (.*)\/200,000 \(Total\)/
    		devotion_status_weekly = $1
    		devotion_status_total = $2
    		break
    	end
    end

  3. Default

    So .* = $1 and the second .* = $2 ? With devotion_status_weekly and devotion_status_total as the variables, correct?

    And the \ is the standard Regex escape. Got it.

    Why the / after total though?

  4. #4

    Default

    Quote Originally Posted by Ramrod View Post
    So .* = $1 and the second .* = $2 ? With devotion_status_weekly and devotion_status_total as the variables, correct?

    And the \ is the standard Regex escape. Got it.

    Why the / after total though?
    The parentheses pairs indicate the capture groups, the pattern inside them is what it's matching to return to the variables to $1 and $2, correlated by the position that they appear in the regex
    .* just means "zero or more of any character", which in this case would match the number that comes before the forward slash in each pair of values. I would personally change them to ([\d,+]) to only match digits and commas, just to be more precise.
    The first and last forward slashes / just indicate the start/end of the regex pattern
    Last edited by Izzy; 08-11-2022 at 12:50 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •