-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRegexFromString.razor
More file actions
85 lines (67 loc) · 2.31 KB
/
Copy pathRegexFromString.razor
File metadata and controls
85 lines (67 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
@using System.Text
@using Fare
@inject IJSRuntime JSRuntime
<div class="container">
<div class="row">
<div class="col">
<label class="label-control">Regular Expression:</label>
<div class="input-group">
<input type="regularExpression" id="regularExpression" name="regularExpression" class="form-control" @bind="RegularExpression">
</div>
</div>
<div class="col">
<label class="label-control">Count:</label>
<div class="input-group">
<input type="count" id="count" name="count" class="form-control" @bind="Count">
</div>
</div>
</div>
<div class="row">
<div class="col">
<button id="Generate" name="Generate" @onclick="Generate" class="btn btn-success float-right">Generate</button>
</div>
</div>
<div class="row">
<div class="col">
<div class="input-group">
<textarea id="output" class="form-control" rows="@Count" @bind="Output"></textarea>
<span class="input-group-btn">
<button id="btnCopy" name="btnCopy" class="btn btn-info float-right" @onclick="Copy"><i class="far fa-copy"></i></button>
</span>
</div>
</div>
</div>
<div class="row">
<div class="col">
<p>Inspired from <a href="https://onlinestringtools.com/generate-string-from-regex" target="_blank">String from Regex Generator</a></p>
</div>
</div>
</div>
@code
{
[Parameter]
public string Output { get; set; }
string RegularExpression;
int Count;
protected override void OnInitialized()
{
RegularExpression = @"\d{1,5}";
Count = 5;
Output = "";
}
private void Generate()
{
StringBuilder builder = new StringBuilder();
for (int i = 0; i < Count; i++)
{
var xeger = new Xeger(RegularExpression);
var random = xeger.Generate();
builder.Append(random + System.Environment.NewLine);
}
Output = builder.ToString().Trim();
}
async Task Copy()
{
await JSRuntime.InvokeVoidAsync("navigator.clipboard.writeText", Output);
}
}