santa hat
deerdeer nosedeer glow
Sign In

Regex for quick conversion of booru tags to SD prompts

Regex for quick conversion of booru tags to SD prompts

Using this regular expression you will be able to quickly convert a list of tags from any picture on Danbooru to a clean prompt for use with Stable Diffusion.

1) Find a picture of the character you want on Danbooru

Use asterisks (*) in the search bar as wildcards. (Searching for 'shirt' will only return the 'shirt' tag, searching for '*shirt*' will return 'shirt', 'red shirt', 'shirt tucked in', 'frilled shirt collar' and so on)

2) When you open an image, all tags related to it will be listed on the left side of the page. Copy them. Not individually, but all of them at once, we're here to make this fast, remember.

We also don't have to worry about organizing tags in alphabetical order as Danbooru does that for us.

artwork: https://www.pixiv.net/en/artworks/111453793
3) Now, navigate to one of the following regular expressions:

a) https://regex101.com/r/DIGBjK/2 (will return tags arranged in a paragraph)

b) https://regex101.com/r/kbNBib/2 (will return tags arranged in a list, each tag in a new line)

4) Paste the tags you copied into the 'Test String' box:

this is what it looks like with a) arranged in a paragraph:

this is what it looks like with b) arranged in a list:

5) Copy the text into your Stable Diffusion UI of choice as a positive prompt and you're good to go.


EXTRA:

For the most part, you'll want to use the first expression as it gives you a ready-to-go prompt, but some may prefer the list if you like to organise your prompts beyond just putting tags in alphabetical order. I, for example, like to split tags for characters depending on the framing of the body and some other factors like so:

taken in ComfyUI

After Sorting:

And now if I want to make a full body picture, I can use this whole prompt, but If I want only a portrait, I can just remove everything below without much thinking. Arms are the only real exception as they may or may not be visible depending on the pose and not just the framing


Raw Expressions:

Regex: (\? )|( \S*.((\n)|$))|( )

Replace (paragraph): ${5:+_}${4:+, }

Replace (list): ${5:+_}${4:+, \n}

Yes, the only difference is the newline (\n)

16

Comments